... and yet another approach (written for generalization) > names(A)[-1][as.matrix(A[,-1])%*%(seq_len(ncol(A)-1))]
[1] "D" "B" "B" "B" "C" "C" "D" Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Thu, Feb 20, 2014 at 4:19 PM, arun <smartpink...@yahoo.com> wrote: > Also, > rownames(which(t(!!A[,-1]),arr.ind=TRUE)) > A.K. > > > > > On Thursday, February 20, 2014 6:48 PM, arun <smartpink...@yahoo.com> wrote: > Hi, > May be this helps: > > A$Variable <- rep(colnames(A[,-1]),nrow(A))[t(!!A[,-1])] > A.K. > > > > On Thursday, February 20, 2014 5:55 PM, ioanna ioannou <ii54...@msn.com> > wrote: > Hello, > > > > > > Assuming that I have a data frame > > A<-data.frame(A=c(10,100,1000,30,50,60,300), > > B=c(0,1,1,1,0,0,0), > > C=c(0,0,0,0,1,1,0), > > D=c(1,0,0,0,0,0,1)) > > > > What I would like is to introduce a new column Variable such that: > > > > A<-data.frame(A=c(10,100,1000,30,50,60,300), > > B=c(0,1,1,1,0,0,0), > > C=c(0,0,0,0,1,1,0), > > D=c(1,0,0,0,0,0,1), > > Variable=c(D,B,B,B,C,C,D)) > > > > How can I do it? > > > > Best > > IOanna > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > > > ______________________________________________ > 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. ______________________________________________ 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.