This is easy to do in the approach I showed.

Instead of:

> names(A)[-1][as.matrix(A[,-1])%*%(seq_len(ncol(A)-1))]

modify it to:

> c("none",names(A)[-1])[as.matrix(A[,-1])%*%seq_len(ncol(A)-1)+1]

[1] "D"    "B"    "B"    "B"    "C"    "C"    "D"    "none"

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 Fri, Feb 21, 2014 at 1:44 AM, ioanna ioannou <ii54...@msn.com> wrote:
> Thank you very much. One further question.
>
> Assuming that for some points there is no classification for example:
>
> A<-data.frame(A=c(10,100,1000,30,50,60,300,3),
>
>               B=c(0,1,1,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))
>
> Is there an easy way to introduce an extra none option in the variable?
>
> A<-data.frame(A=c(10,100,1000,30,50,60,300,3),
>
>               B=c(0,1,1,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: 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 <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.

Reply via email to