Johnny Liseth
2012-Apr-13 23:33 UTC
[R] Merging two data frames with different columns names
I am trying to merge two data frames, but one of the column headings are different in the two frames. How can I rjoin or rbind the tho frames? Johnny # Generate 2 blocks by confounding on abc d1 <- conf.design(c(1,1,1), p=2, block.name="blk", treatment.names c("A","B","C")) d2 <- conf.design(c(1,1,1), p=2, block.name="blk", treatment.names c("A","B","C")) rep1 <- c(550,669,633,642,1037,749,1075,729) rep2 <- c(604,650,601,635,1052,868,1063,860) part1 <- data.frame(d1,rep1) part2 <- data.frame(d2,rep2) d12 <- rbind(part1,part2) [[alternative HTML version deleted]]
I guess you just want one data.frame with the columns part1 and part2? Then: merge(part1, part2) should do thr trick. If you aim at something different, please explain you expected result. Uwe Ligges On 14.04.2012 01:33, Johnny Liseth wrote:> I am trying to merge two data frames, but one of the column headings are > different in the two frames. How can I rjoin or rbind the tho frames? > > Johnny > > # Generate 2 blocks by confounding on abc > d1<- conf.design(c(1,1,1), p=2, block.name="blk", treatment.names > c("A","B","C")) > d2<- conf.design(c(1,1,1), p=2, block.name="blk", treatment.names > c("A","B","C")) > > rep1<- c(550,669,633,642,1037,749,1075,729) > rep2<- c(604,650,601,635,1052,868,1063,860) > > part1<- data.frame(d1,rep1) > part2<- data.frame(d2,rep2) > > d12<- rbind(part1,part2) > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Hi everyone, I have a quick question about the random part in lme(). Here is the code:> lme(WBEING~HRS+LEAD+G.HRS,random=~LEAD|GRP)I want to specify both random intercept and random slope of LEAD. Is the random intercept already in it? or should I specify it like:> lme(WBEING~HRS+LEAD+G.HRS,random=~1+LEAD|GRP) ?Thank you very much. Best regards, YA
Pete Brecknock
2012-Apr-14 20:26 UTC
[R] Merging two data frames with different columns names
Peterso wrote> > Uwe: > > I was actually trying to stack one table on top of the other. All column > names are the same except for the Part1 and Part 2. My final table should > look like the table below. Maybe it is possible to change the names of > Part1 and Part 2 to Part? > > A B C Part > 1 0 1 550 > 0 1 1 669 > etc.... >A couple of approaches using the rbind function ... require(conf.design) # Your Data d1 <- conf.design(c(1,1,1), p=2, block.name="blk", treatment.names c("A","B","C")) d2 <- conf.design(c(1,1,1), p=2, block.name="blk", treatment.names c("A","B","C")) rep1 <- c(550,669,633,642,1037,749,1075,729) rep2 <- c(604,650,601,635,1052,868,1063,860) # Approach 1 part1 <- data.frame(d1,part=rep1) part2 <- data.frame(d2,part=rep2) d12 <- rbind(part1,part2) # Approach 2 part1 <- data.frame(d1,rep1) names(part1)<- c("blk","A","B","C","part") part2 <- data.frame(d2,rep2) names(part2)<- c("blk","A","B","C","part") d12 <- rbind(part1, part2) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Merging-two-data-frames-with-different-columns-names-tp4556400p4557974.html Sent from the R help mailing list archive at Nabble.com.
Both specifications are the same model. An intercept is added by default unless you use +0 or -1 like ~0 + LEAD|GRP or ~ -1 + LEAD|GRP ________________________________________ Van: r-help-bounces at r-project.org [r-help-bounces at r-project.org] namens YA [xinxi813 at 163.com] Verzonden: zaterdag 14 april 2012 18:33 Aan: r-help at r-project.org Onderwerp: [R] quick question about lme() Hi everyone, I have a quick question about the random part in lme(). Here is the code:> lme(WBEING~HRS+LEAD+G.HRS,random=~LEAD|GRP)I want to specify both random intercept and random slope of LEAD. Is the random intercept already in it? or should I specify it like:> lme(WBEING~HRS+LEAD+G.HRS,random=~1+LEAD|GRP) ?Thank you very much. Best regards, YA ______________________________________________ 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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
Hi Thierry, Thank you very much. Best regards, YA On 2012-4-15 1:06, ONKELINX, Thierry wrote:> Both specifications are the same model. An intercept is added by default unless you use +0 or -1 > like ~0 + LEAD|GRP or ~ -1 + LEAD|GRP > ________________________________________ > Van: r-help-bounces at r-project.org [r-help-bounces at r-project.org] namens YA [xinxi813 at 163.com] > Verzonden: zaterdag 14 april 2012 18:33 > Aan: r-help at r-project.org > Onderwerp: [R] quick question about lme() > > Hi everyone, > > I have a quick question about the random part in lme(). > > Here is the code: > >> lme(WBEING~HRS+LEAD+G.HRS,random=~LEAD|GRP) > I want to specify both random intercept and random slope of LEAD. Is the > random intercept already in it? or should I specify it like: > >> lme(WBEING~HRS+LEAD+G.HRS,random=~1+LEAD|GRP) ? > Thank you very much. > > Best regards, > > YA > > ______________________________________________ > 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. > * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * > Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. > The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.