[R] help "reshaping" dataframe
Jim Lemon
jim at bitwrit.com.au
Sat Jan 5 06:26:45 CET 2013
On 01/05/2013 10:15 AM, Andrea Goijman wrote:
...
Hi Andrea,
This may be what you want:
occ.data<-data.frame(year=rep(2003,20),Ruta=rep(202,20),
+ Point=c(3,4,1,1,2,3,4,1,4,5,1,3,4,5,1,4,5,10,7,8),
+ Site=c(rep(2021,17),rep(2022,3)),
+ specie=c("MICH","MICH","MISA","MOBO","MOBO","MOBO","MOBO",
+ "SILU","SILU","TYSA","ZEAU","ZEAU","ZEAU","ZEAU","ZOCA","ZOCA",
+ "ZOCA","MICH","MISA","MISA"),Pres=rep(1,20),
+ Rep=c(3,4,1,1,2,3,4,1,4,5,1,3,4,5,1,4,5,5,2,3))
> library(prettyR)
> stretch_df(occ.data,idvar="specie",to.stretch="Rep",
> ordervar="Pres",include.ordervar=FALSE)
specie year Ruta Point Site Rep_1 Rep_2 Rep_3 Rep_4
1 MICH 2003 202 3 2021 3 4 5 NA
2 MISA 2003 202 1 2021 1 2 3 NA
3 MOBO 2003 202 1 2021 1 2 3 4
4 SILU 2003 202 1 2021 1 4 NA NA
5 TYSA 2003 202 5 2021 5 NA NA NA
6 ZEAU 2003 202 1 2021 1 3 4 5
7 ZOCA 2003 202 1 2021 1 4 5 NA
Jim
More information about the R-help
mailing list