Tammy Ma
2013-Jan-22 09:28 UTC
[R] How to align group based on the common values of two columns in r
HI, I met this problem: I have the feature data frame: Feature OS 4 2 4 1 4 3 1 2 4 1 what I want to do is to autimatically create one more column called "group": Feature OS Group 4 2 1 4 1 2 4 3 3 1 2 4 4 1 2 I don't want "Ifelse", because I have so many combination of feature and OS, I even can not account. I just want to have sth to autimatically create group indicator based on the difference combination of feature and OS. Thanks for your help. Kind regards, Tammy [[alternative HTML version deleted]]
Gerrit Eichner
2013-Jan-22 09:38 UTC
[R] How to align group based on the common values of two columnsinr
Hi, Tammy, maybe you find something interesting looking at ?interaction and/or try (with df being your data frame) df$Group <- as.integer( with( df, interaction( Feature, OS)[, drop = TRUE])) HtH -- Gerrit On Tue, 22 Jan 2013, Tammy Ma wrote:> > HI, > > I met this problem: > > I have the feature data frame: > > > Feature OS > 4 2 > 4 1 > 4 3 > 1 2 > 4 1 > > > what I want to do is to autimatically create one more column called "group": > > Feature OS Group > 4 2 1 > 4 1 2 > 4 3 3 > 1 2 4 > 4 1 2 > > > > I don't want "Ifelse", because I have so many combination of feature and OS, I even can not account. I just want to have sth to autimatically create group indicator based on the difference combination of feature and OS. > > Thanks for your help. > > > Kind regards, > Tammy > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
arun
2013-Jan-22 13:50 UTC
[R] How to align group based on the common values of two columns in r
Hi, I am not sure about the logic behind creation of groups, especially, how do you want to assign the group number to a particular combination of Feature and OS. One possible way would be: ?dat1$Group<-paste(dat1[,1],dat1[,2],sep="")> dat1#? Feature OS Group #1?????? 4? 2??? 42 #2?????? 4? 1??? 41 #3?????? 4? 3??? 43 #4?????? 1? 2??? 12 #5?????? 4? 1??? 41 A.K. ----- Original Message ----- From: Tammy Ma <metal_licaling at live.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Tuesday, January 22, 2013 4:28 AM Subject: [R] How to align group based on the common values of two columns in r HI, I met this problem: I have the feature data frame: ? Feature? ? OS ? ? 4? ? ? ? ? ? ? 2 ? ? 4? ? ? ? ? ? ? 1 ? ? 4? ? ? ? ? ? ? 3 ? ? 1? ? ? ? ? ? ? 2 ? ? 4? ? ? ? ? ? ? 1 what I want to do is to autimatically create one more column called "group": ? Feature? ? OS? ? ? Group ? ? 4? ? ? ? ? ? ? 2? ? ? ? 1 ? ? 4? ? ? ? ? ? ? 1? ? ? ? 2 ? ? 4? ? ? ? ? ? ? 3? ? ? ? 3 ? ? 1? ? ? ? ? ? ? 2? ? ? ? 4 ? ? 4? ? ? ? ? ? ? 1? ? ? ? 2 I don't want "Ifelse", because I have so many combination of feature and OS, I even can not account.? I just want to have sth to autimatically create group indicator based on the difference combination of feature and OS. Thanks for your help. Kind regards, Tammy ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
arun
2013-Jan-22 18:58 UTC
[R] How to align group based on the common values of two columns in r
Hi, You could also try: dat1<-read.table(text=" ?Feature??? OS ??? 4????????????? 2 ??? 4????????????? 1 ??? 4????????????? 3 ??? 1????????????? 2 ??? 4????????????? 1 ",sep="",header=TRUE) ?dat1$Group<- as.numeric(factor(Reduce(paste0,dat1))) A.K. ----- Original Message ----- From: Tammy Ma <metal_licaling at live.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Tuesday, January 22, 2013 4:28 AM Subject: [R] How to align group based on the common values of two columns in r HI, I met this problem: I have the feature data frame: ? Feature? ? OS ? ? 4? ? ? ? ? ? ? 2 ? ? 4? ? ? ? ? ? ? 1 ? ? 4? ? ? ? ? ? ? 3 ? ? 1? ? ? ? ? ? ? 2 ? ? 4? ? ? ? ? ? ? 1 what I want to do is to autimatically create one more column called "group": ? Feature? ? OS? ? ? Group ? ? 4? ? ? ? ? ? ? 2? ? ? ? 1 ? ? 4? ? ? ? ? ? ? 1? ? ? ? 2 ? ? 4? ? ? ? ? ? ? 3? ? ? ? 3 ? ? 1? ? ? ? ? ? ? 2? ? ? ? 4 ? ? 4? ? ? ? ? ? ? 1? ? ? ? 2 I don't want "Ifelse", because I have so many combination of feature and OS, I even can not account.? I just want to have sth to autimatically create group indicator based on the difference combination of feature and OS. Thanks for your help. Kind regards, Tammy ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.