[R] data.frame transformation
Christian Hof
chof at bi.ku.dk
Wed Jan 30 19:47:43 CET 2008
Dear all,
maybe somebody can provide some help for this problem:
Example:
I've got the following dataframe "data":
grid.id<-c(1:4)
lat<-c(10,12,13,15)
species1<-c(0,0,0,1)
species2<-c(1,1,0,0)
species3<-c(1,1,1,1)
data<-data.frame(cbind(grid.id,lat,species1,species2,species3))
How can I, out of "data" make a new dataframe, where the cells of value
"1" in the species columns ("species1" to "species3") are replaced by
the respective "lat" values automatically - so that the final dataframe
looks like this:
specieslat1<-c(0,0,0,15)
specieslat2<-c(10,12,0,0)
specieslat3<-c(10,12,13,15)
data.frame(cbind(grid.id,lat,specieslat1,specieslat2,specieslat3))
?
Thanks a lot,
cheers
Christian
--
Christian Hof .. PhD student
Biodiversity & Global Change Lab .. C/José Gutiérrez Abascal, 2
Museo Nacional de Ciencias Naturales .. E-28006 Madrid (España)
www.biochange-lab.eu
Center for Macroecology .. University of Copenhagen
www.macroecology.ku.dk
mobile ES .. +34 697 508 519
mobile DE .. +49 176 205 189 27
mail .. chof at bi.ku.dk
blog .. www.vogelwart.de
More information about the R-help
mailing list