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.prese
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)
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
-project.org] On Behalf Of AllenL
> Sent: 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 m
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:
5 matches
Mail list logo