Re: [R] Another newbie question

2009-01-08 Thread AllenL
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)

Re: [R] Another newbie question

2009-01-07 Thread Peter Alspach
: Thursday, 8 January 2009 7:28 a.m. To: r-help@r-project.org Subject: [R] Another newbie question 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

Re: [R] Another newbie question

2009-01-07 Thread jim holtman
You did not provide any data, so I will take a guess at what it looks like: x - matrix(sample(0:1, 100, TRUE), 10) colnames(x) - LETTERS[1:10] x - as.data.frame(x) x A B C D E F G H I J 1 0 1 0 0 0 1 1 0 0 0 2 0 0 0 0 1 1 0 0 1 0 3 1 1 0 0 1 0 0 0 1 1 4 0 1 1 1 0 1 1 0 0 0 5 0 1 1 0 0

Re: [R] Another newbie question

2009-01-07 Thread Dimitris Rizopoulos
try the following: dat - data.frame( sp1 = rbinom(10, 1, 0.5), sp2 = rbinom(10, 1, 0.5), sp3 = rbinom(10, 1, 0.5), sp4 = rbinom(10, 1, 0.5), sp5 = rbinom(10, 1, 0.5), sp6 = rbinom(10, 1, 0.5) ) ind - sapply(dat, as.logical) dat$Sp - apply(ind, 1, function (x, nams)