Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread arun
- Original Message - From: William Dunlap To: arun ; "stude...@gmail.com" Cc: R help Sent: Monday, May 13, 2013 12:13 PM Subject: RE: [R] reduce three columns to one with the colnames If the dataset is large you may prefer to process it by column instead of by row.  E.g.,   > m

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread Gabor Grothendieck
On Mon, May 13, 2013 at 11:22 AM, David Studer wrote: > OK, seems like nobody understood my question ;-) > > Let's make another example: > > I have three variables: > data$male and data$female and data$transsexuals > > All the three of them contain the values 0 and 1. > > Now I'd like to create an

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread Bert Gunter
... and I could not resist adding (assuming the vectors are all in a data frame or matrix, yourdat): apply(yourdat,1,function(x)c("blue","green","red")[as.logical(x)]) Cheers, Bert On Mon, May 13, 2013 at 8:39 AM, Gabor Grothendieck wrote: > On Mon, May 13, 2013 at 10:24 AM, David Studer wr

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread William Dunlap
roject.org] On > Behalf > Of arun > Sent: Monday, May 13, 2013 8:37 AM > To: stude...@gmail.com > Cc: R help > Subject: Re: [R] reduce three columns to one with the colnames > > HI, > May be: > dat1<- read.table(text=" > male female transsexuals > 0 1

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread Gabor Grothendieck
On Mon, May 13, 2013 at 10:24 AM, David Studer wrote: > Hello everybody, > > I have three variables "blue", "green" and "red" containing values 0 (no) > and 1 (yes). > > How can I easily create another variable "colors" with the values "blue", > "green" and "red"? > Suppose blue <- c(1, 0, 0, 1)

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread arun
om: David Studer To: Bert Gunter Cc: r-help@r-project.org Sent: Monday, May 13, 2013 11:22 AM Subject: Re: [R] reduce three columns to one with the colnames OK, seems like nobody understood my question ;-) Let's make another example: I have three variables: data$male and data$female and data

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread David Studer
OK, seems like nobody understood my question ;-) Let's make another example: I have three variables: data$male and data$female and data$transsexuals All the three of them contain the values 0 and 1. Now I'd like to create another variable data$sex. Now in all cases where data$female==1 the vari

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread Bert Gunter
No -- my answer is wrong. I'll leave it to others to correct. Obvious question to OP: What if more than one of your colors variables simultaneously have a 1? -- Bert On Mon, May 13, 2013 at 8:09 AM, Bert Gunter wrote: > Cute answer, Pascal. It may even be the answer to the question the OP > shou

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread Bert Gunter
Cute answer, Pascal. It may even be the answer to the question the OP should have asked, but I don't think it answered the question that was asked. That might be: c("red"[red], "green"[green], "blue"[blue]) Cheers, Bert On Mon, May 13, 2013 at 7:36 AM, Pascal Oettli wrote: > Hi, > > ?rgb > > HT

Re: [R] reduce three columns to one with the colnames

2013-05-13 Thread Pascal Oettli
Hi, ?rgb HTH Pascal 2013/5/13 David Studer > Hello everybody, > > I have three variables "blue", "green" and "red" containing values 0 (no) > and 1 (yes). > > How can I easily create another variable "colors" with the values "blue", > "green" and "red"? > > I hope that you can understand my q

[R] reduce three columns to one with the colnames

2013-05-13 Thread David Studer
Hello everybody, I have three variables "blue", "green" and "red" containing values 0 (no) and 1 (yes). How can I easily create another variable "colors" with the values "blue", "green" and "red"? I hope that you can understand my question and appreciate any solutions or hints! Thank you! David