Hi, May be this helps you.
source("Andreadata.txt") head(occ.data) melting<- melt(occ.data,id.var=c("Point", "Site", "Rep", "Año"),measure.var="Pres") y<-cast(melting,Site~Rep~Point~Año) dim(y) #[1] 10 5 25 6 y[,,25,6] # Rep #Site 1 2 3 4 5 # 1021 0 0 0 0 0 # 1022 0 0 0 0 0 # 1051 0 0 0 0 0 # 2073 0 0 0 0 0 # 2194 0 0 0 0 0 # 2195 0 0 0 0 0 # 3055 0 0 0 0 7 # 4072 0 0 0 0 0 # 4073 0 0 0 0 0 # 6202 0 0 0 0 0 library(plyr) y1<-aaply(y,1,function(x) {x[x>1]<-1;x}) dim(y1) #[1] 10 5 25 6 y1[,,25,6] # Rep #Site 1 2 3 4 5 # 1021 0 0 0 0 0 # 1022 0 0 0 0 0 # 1051 0 0 0 0 0 # 2073 0 0 0 0 0 # 2194 0 0 0 0 0 # 2195 0 0 0 0 0 # 3055 0 0 0 0 1 # 4072 0 0 0 0 0 # 4073 0 0 0 0 0 # 6202 0 0 0 0 0 A.K. ----- Original Message ----- From: Andrea Goijman <agoij...@cnia.inta.gov.ar> To: R help <r-help@r-project.org> Cc: Sent: Wednesday, January 16, 2013 10:42 AM Subject: [R] Changing frequency values to 1 and 0 Dear list, I'm working with a large data set, where I grouped several species in one group (guild). Then I reshaped my data as shown below. Now, I just want to have "Rep" only as 1 or 0. I'm not being able to change the values of rep>=1 to 1... tried many things and I'm not being successful! > melting=melt(occ.data,id.var=c("guild", "Site", "Rep", "Año"), measure.var="Pres") > y=cast(melting, Site ~ Rep ~ guild ~ Año) Aggregation requires fun.aggregate: length used as default > y[1:10,,"gui4a",1:2] , , Año = 2003 Rep Site 1 2 3 4 5 1021 0 0 0 0 0 1022 0 0 0 0 0 1023 0 0 0 0 0 1024 0 0 0 0 0 1025 0 0 0 0 0 1026 0 0 0 0 0 * 1051 3 1 2 3 5* * 1052 4 3 5 2 3* * 1053 4 3 3 3 2* * 1054 1 2 1 3 0* , , Año = 2004 Rep Site 1 2 3 4 5 1021 2 5 5 5 4 1022 6 3 2 2 2 1023 4 1 1 2 2 1024 0 1 2 2 0 1025 0 1 0 1 0 1026 2 1 0 0 1 1051 2 1 3 1 2 1052 2 4 1 1 2 1053 2 4 2 2 1 1054 4 3 3 2 3 [[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. ______________________________________________ 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.