Re: [R] Data manipulation in a data.frame

2014-02-21 Thread arun
Hi Ioanna, If you need to paste the colnames if there are multiple 1's per row: You could try: A<-data.frame(A=c(10,100,1000,30,50,60,300,3,4,2,20,35,45),B=c(0,1,1,1,0,0,0,0,0,1,0,0,1),C=c(0,0,0,0,1,1,0,0,0,0,1,1,1),D=c(1,0,0,0,0,0,1,0,0,1,NA,1,1)) apply(A[,-1],1,function(x) {x1 <-paste(colnames(A[

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread Bert Gunter
,1,0,0,0,0), > > C=c(0,0,0,0,1,1,0,0), > > D=c(1,0,0,0,0,0,1,0), > >Variable=c(D,B,B,B,C,C,D,none)) > > Thanks in advance, > IOanna > > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread arun
mailto:smartpink...@yahoo.com] Sent: 21 February 2014 00:19 To: r-help@r-project.org Cc: ioanna ioannou Subject: Re: [R] 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 wrote: Hi, May be this helps: A$V

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread Bert Gunter
t; D=c(1,0,0,0,0,0,1,0), > >Variable=c(D,B,B,B,C,C,D,none)) > > Thanks in advance, > IOanna > > -Original Message- > From: arun [mailto:smartpink...@yahoo.com] > Sent: 21 February 2014 00:19 > To: r-help@r-project.org > Cc: ioanna ioannou &

Re: [R] Data manipulation in a data.frame

2014-02-21 Thread ioanna ioannou
D,none)) Thanks in advance, IOanna -Original Message- From: arun [mailto:smartpink...@yahoo.com] Sent: 21 February 2014 00:19 To: r-help@r-project.org Cc: ioanna ioannou Subject: Re: [R] Data manipulation in a data.frame Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K. On Thursday, Fe

Re: [R] Data manipulation in a data.frame

2014-02-20 Thread Bert Gunter
... 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

Re: [R] Data manipulation in a data.frame

2014-02-20 Thread arun
Also, rownames(which(t(!!A[,-1]),arr.ind=TRUE)) A.K. On Thursday, February 20, 2014 6:48 PM, arun 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 wrote: Hello, Assuming that I have a da

Re: [R] Data manipulation in a data.frame

2014-02-20 Thread arun
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 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),                     

[R] Data manipulation in a data.frame

2014-02-20 Thread ioanna ioannou
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: