Skip to content
Prev 336845 / 398513 Next

Data manipulation in a data.frame

Also,
rownames(which(t(!!A[,-1]),arr.ind=TRUE))
A.K.
On Thursday, February 20, 2014 6:48 PM, arun <smartpink111 at 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 <ii54250 at 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 at 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.