Re: [R] Creating a new column from a series of columns

2014-10-31 Thread Jeff Newmiller
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" ) ]

Re: [R] Creating a new column from a series of columns

2014-10-31 Thread Jorge I Velez
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] Creating a new column from a series of columns

2014-10-31 Thread Fisher Dennis
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