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