[R] Another newbie question

AllenL allen.larocque at gmail.com
Thu Jan 8 21:28:26 CET 2009


Thank you all! In future I will include examples of my code to make things
simpler for you. This is what I settled on:

Sp.presence<-Data[,14:31]   ##The subset of my data set I'm interested in
(the presence/absence data)
Sp.presence$Species<-apply(Sp.presence,1,function(x)
{c(paste(names(Sp.presence)[x==1],collapse=","))})

Yay!
-Allen



AllenL wrote:
> 
> Problem: 
> I have a data frame with 1s and 0s denoting presence/absence of species
> (columns) for particular plot measurements (rows). What I want to do is
> make a new column whose entries for each row is a list of the column names
> in which a species is present (ie. for row one its entry might read:
> "sp1","sp2", etc.). I've tried various functions etc. but can't seem to
> get the syntax right/ the correct combination of functions.
> Thanks in advance!
> -Allen
> 
> 

-- 
View this message in context: http://www.nabble.com/Another-newbie-question-tp21337371p21360273.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list