Thanks all!

These 2 options worked great.


### OPTION 1
u<-with(occ.data,ftable(Rep~Año+Site+Especie+Pres))
u[1:5,]
library(reshape2)
flat.occ<-dcast(as.data.frame(u), Año + Site + Especie + Pres ~ Rep, fill =
0)
flat.occ[1:10,]


### OPTION 2

occ.data1<-occ.data[,-c(2:3)]
library(reshape2)
flat.occ<-dcast(occ.data1,Año+Site+Especie+Pres~Rep,value.var="Rep")
flat.occ[,-c(1:4)]<-sapply(flat.occ[,-c(1:4)],function(x) as.integer(is.na
(x)))
flat.occ[1:10,]


On Sat, Jan 5, 2013 at 12:26 AM, Jim Lemon <j...@bitwrit.com.au> wrote:

> 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
>



-- 
---
Lic. Andrea Paula Goijman
Grupo Ecología y Gestión Ambiental de la Biodiversidad
IRB - INTA Castelar, Argentina
agoij...@cnia.inta.gov.ar
 <http://inta.gob.ar/personas/goijman.andrea/>
http://inta.gob.ar/personas/goijman.andrea/

PhD Candidate
Georgia Cooperative Fish and Wildlife Research Unit
D.B. Warnell School of Forestry and Natural Resources
University of Georgia
Athens, GA 30602 USA
Tel. +706.206.4805
andre...@uga.edu

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to