This method handles cases where multiple columns are "Yes".
library(reshape2)
ddl <- melt( dd, id.vars = "PLTID" )
ddl[ is.na( ddl$value ), "value" ] <- ""
ddl <- ddl[ "Yes" == ddl$value, ]
result <- merge( dd[ , "PLTID", drop=FALSE ]
, ddl[ , c( "PLTID", "variable", "value" ) ]
Dear Dennis,
Assuming that your data.frame() is called dd, the following should get you
started:
colnames(dd[,-1])[apply(dd[,-1], 1, function(x) which(x == 'Yes'))]
HTH,
Jorge.-
On Sat, Nov 1, 2014 at 12:32 PM, Fisher Dennis wrote:
> R 3.1.1
> OS X
>
> Colleagues,
> I have a dataset containi
R 3.1.1
OS X
Colleagues,
I have a dataset containing multiple columns indicating race for subjects in a
clinical trial. A subset of the data (obtained with dput) is shown here:
structure(list(PLTID = c(7157, 8138, 8150, 9112, 9114, 9115,
9124, 9133, 9141, 9144, 9148, 12110, 12111, 12116, 12134
3 matches
Mail list logo