Is there a way to combine two columns within a data frame? Example data: id snp AL1 AL2 1500 30 A B 1510 30 A A 1520 30 A B This is what I would like: indv snp AL1AL2 1500 30 AB 1510 30 AA 1520 30 AB Any help is greatly appreciated. Alysta
Try: transform(x, AL1Al2 = paste(AL1, AL2, sep=''))[-c(3:4)] On 07/03/2008, amarkey at uiuc.edu <amarkey at uiuc.edu> wrote:> Is there a way to combine two columns within a data frame? > > Example data: > > id snp AL1 AL2 > 1500 30 A B > 1510 30 A A > 1520 30 A B > > This is what I would like: > > indv snp AL1AL2 > 1500 30 AB > 1510 30 AA > 1520 30 AB > > Any help is greatly appreciated. > > Alysta > > ______________________________________________ > R-help at 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Depending on your purpose you might want to look at ?interaction or its synonym : (i.e. a colon) On Fri, Mar 7, 2008 at 4:09 PM, <amarkey at uiuc.edu> wrote:> Is there a way to combine two columns within a data frame? > > Example data: > > id snp AL1 AL2 > 1500 30 A B > 1510 30 A A > 1520 30 A B > > This is what I would like: > > indv snp AL1AL2 > 1500 30 AB > 1510 30 AA > 1520 30 AB > > Any help is greatly appreciated. > > Alysta > > ______________________________________________ > R-help at 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. >
That worked perfectly. Thank you!!! ---- Original message ---->Date: Fri, 7 Mar 2008 18:13:24 -0300 >From: "Henrique Dallazuanna" <wwwhsd at gmail.com> >Subject: Re: [R] Combine two columns >To: "amarkey at uiuc.edu" <amarkey at uiuc.edu> >Cc: r-help at r-project.org > >Try: > >transform(x, AL1Al2 = paste(AL1, AL2, sep=''))[-c(3:4)] > >On 07/03/2008, amarkey at uiuc.edu <amarkey at uiuc.edu> wrote: >> Is there a way to combine two columns within a data frame? >> >> Example data: >> >> id snp AL1 AL2 >> 1500 30 A B >> 1510 30 A A >> 1520 30 A B >> >> This is what I would like: >> >> indv snp AL1AL2 >> 1500 30 AB >> 1510 30 AA >> 1520 30 AB >> >> Any help is greatly appreciated. >> >> Alysta >> >> ______________________________________________ >> R-help at 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. >> > > >-- >Henrique Dallazuanna >Curitiba-Paran?-Brasil >25? 25' 40" S 49? 16' 22" O