Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread A M Lavezzi
> -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of S Ellison > Sent: Friday, May 26, 2017 8:28 AM > To: A M Lavezzi <mario.lave...@unipa.it>; r-help <r-help@r-project.org> > Subject: Re: [R] organizing data in a matrix avoiding

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread A M Lavezzi
Thanks a lot for your suggestion. I followed the suggestion of Sarah (the first on the thread) and solved my problem I will keep into account you suggestion anyway Mario On Fri, May 26, 2017 at 3:28 PM, S Ellison wrote: > > -Original Message- > > From: A M >

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread A M Lavezzi
Hi Duncan thanks a lot for your suggestion. I followed the suggestion of Sarah (the first on the thread) and solved my problem I will keep into account you suggestion anyway Mario On Fri, May 26, 2017 at 2:20 PM, Duncan Murdoch wrote: > On 26/05/2017 7:46 AM, A M

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread A M Lavezzi
Hi Ulrik thanks a lot for your suggestion. I followed the suggestion of Sarah (the first on the thread) and solved my problem I will keep into account you suggestion anyway Mario On Fri, May 26, 2017 at 2:17 PM, Ulrik Stervbo wrote: > Hi Mario, > > does acast from the

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread A M Lavezzi
Dear Sarah thank you very much. I used "crosstab" and it worked, xxx<-crosstab(dataTrade$iso_o,dataTrade$iso_d,dataTrade$FLOW,type="sum",na.rm=TRUE) All the best Mario On Fri, May 26, 2017 at 2:15 PM, Sarah Goslee wrote: > There are various ways to do this. It

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread David L Carlson
: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of S Ellison Sent: Friday, May 26, 2017 8:28 AM To: A M Lavezzi <mario.lave...@unipa.it>; r-help <r-help@r-project.org> Subject: Re: [R] organizing data in a matrix avoiding loop > -Original Message- > From: A M >

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread S Ellison
> -Original Message- > From: A M > Lavezzi > > I have data on bilateral trade flows among countries in the following form: > > iso_o iso_d year FLOW > 1 ABW AFG 1985 NA > 2 ABW AFG 1986 NA > 3 ABW AFG 1987 NA > 4 ABW AFG 1988 NA > 5 ABW AFG 1989 NA > 6

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread Duncan Murdoch
On 26/05/2017 7:46 AM, A M Lavezzi wrote: Dear R-Users I have data on bilateral trade flows among countries in the following form: head(dataTrade) iso_o iso_d year FLOW 1 ABW AFG 1985 NA 2 ABW AFG 1986 NA 3 ABW AFG 1987 NA 4 ABW AFG 1988 NA 5 ABW AFG 1989

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread Ulrik Stervbo
Hi Mario, does acast from the reshape2 package help? dfa<- data.frame(iso_o = letters[c(1, 1:4)], iso_d = letters[6:10], year = c(1985, 1985, 1986, 1987, 1988), flow = c(1,2,3,4, NA)) reshape2::acast(dfa, iso_o ~ iso_d, fun.aggregate = sum, value.var = "flow") HTH Ulrik On Fri, 26 May 2017 at

Re: [R] organizing data in a matrix avoiding loop

2017-05-26 Thread Sarah Goslee
There are various ways to do this. It shouldn't take forever as a loop, with only 215 entries. I find crosstab() from the ecodist package helpful. The current version is on GitHub, but not yet CRAN (soon!). Sarah On Fri, May 26, 2017 at 7:47 AM A M Lavezzi wrote: >

[R] organizing data in a matrix avoiding loop

2017-05-26 Thread A M Lavezzi
Dear R-Users I have data on bilateral trade flows among countries in the following form: > head(dataTrade) iso_o iso_d year FLOW 1 ABW AFG 1985 NA 2 ABW AFG 1986 NA 3 ABW AFG 1987 NA 4 ABW AFG 1988 NA 5 ABW AFG 1989 NA 6 ABW AFG 1990 NA where: iso_o: