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[
,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
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
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
&
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
... 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
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
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),
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:
9 matches
Mail list logo