Hi and thank you in advance, If I have a dataframe, df: Sample Plot Biomass 1 1 1024 1 2 32 2 3 223 2 4 456 3 1 3 2 331 3 3 22151 3 4 1441 And another one, df1: Sample Plot % cover of plant1 % cover of plant2 3 1 32 63 3 2 3 3 3 3 3 4 5 23 I want to join these tables where the columns Sample and Plot are the same. Currently trying: df<- right_join(df, df1, by = c(?Sample?, "Plot")) I am working with a much larger dataset, but it will cut off the data starting at Sample 3 instead of joining the tables while retaining the information from df. Any ideas how I could join them this way? Esthi [[alternative HTML version deleted]]
1) Compare the text below that the mailing list sent us to what you saw when you sent your post... this occurred because you did not follow the instructions in the Posting Guide that tell you to send plain text email... the mailing list strips formatting. Note that there are far too many email clients for the Posting Guide to provide instructions on how to configure your particular email client to send plain text, but it is always an option. 2) `right_join` is not a base R function, so you should be specifying which contributed package it comes from. 3) If it comes from dplyr, then you should take note that right_join is not actually used very often in practice. Have you tried left_join? On June 29, 2021 8:12:28 AM PDT, Esthi Erickson <ericksonesthi at gmail.com> wrote:>Hi and thank you in advance, > >If I have a dataframe, df: > >Sample > >Plot > >Biomass > >1 > >1 > >1024 > >1 > >2 > >32 > >2 > >3 > >223 > >2 > >4 > >456 > >3 > >1 > > >3 > >2 > >331 > >3 > >3 > >22151 > >3 > >4 > >1441 > >And another one, df1: > >Sample > >Plot > >% cover of plant1 > >% cover of plant2 > >3 > >1 > >32 > >63 > >3 > >2 > >3 > > >3 > >3 > > >3 > >3 > >4 > >5 > >23 > >I want to join these tables where the columns Sample and Plot are the >same. > >Currently trying: > >df<- right_join(df, df1, by = c(?Sample?, "Plot")) > >I am working with a much larger dataset, but it will cut off the data >starting at Sample 3 instead of joining the tables while retaining the >information from df. Any ideas how I could join them this way? > > >Esthi > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.-- Sent from my phone. Please excuse my brevity.
This is a plain text list: do not post in HTML -- it can get mangled, as here (see quoted text below). Also, you have not posted a reprex; doing so would make it more likely that you get a helpful reply. Anyway, I *think* you may want a full outer join, which, In base R, is simply given by: newdf <- merge(df1, df2, all = TRUE) ?merge gives you more info to get what you may want if I'm wrong. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Jun 29, 2021 at 8:13 AM Esthi Erickson <ericksonesthi at gmail.com> wrote:> Hi and thank you in advance, > > If I have a dataframe, df: > > Sample > > Plot > > Biomass > > 1 > > 1 > > 1024 > > 1 > > 2 > > 32 > > 2 > > 3 > > 223 > > 2 > > 4 > > 456 > > 3 > > 1 > > > 3 > > 2 > > 331 > > 3 > > 3 > > 22151 > > 3 > > 4 > > 1441 > > And another one, df1: > > Sample > > Plot > > % cover of plant1 > > % cover of plant2 > > 3 > > 1 > > 32 > > 63 > > 3 > > 2 > > 3 > > > 3 > > 3 > > > 3 > > 3 > > 4 > > 5 > > 23 > > I want to join these tables where the columns Sample and Plot are the same. > > Currently trying: > > df<- right_join(df, df1, by = c(?Sample?, "Plot")) > > I am working with a much larger dataset, but it will cut off the data > starting at Sample 3 instead of joining the tables while retaining the > information from df. Any ideas how I could join them this way? > > > Esthi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >[[alternative HTML version deleted]]
hi. i would suggest re-formatting your message as plain text (not HTML), and re-sending it. this list strips out HTML content, and the plain text version you sent is close to illegible. cheers, Greg
Hi Esthi, Have you tried something like: df2<-merge(df,df1,by.x="Sample",by.y="Plot",all.y=TRUE) This will get you a right join in "df2", not overwriting "df". Jim On Wed, Jun 30, 2021 at 1:13 AM Esthi Erickson <ericksonesthi at gmail.com> wrote:> > Hi and thank you in advance, > > If I have a dataframe, df: > > Sample > > Plot > > Biomass > > 1 > > 1 > > 1024 > > 1 > > 2 > > 32 > > 2 > > 3 > > 223 > > 2 > > 4 > > 456 > > 3 > > 1 > > > 3 > > 2 > > 331 > > 3 > > 3 > > 22151 > > 3 > > 4 > > 1441 > > And another one, df1: > > Sample > > Plot > > % cover of plant1 > > % cover of plant2 > > 3 > > 1 > > 32 > > 63 > > 3 > > 2 > > 3 > > > 3 > > 3 > > > 3 > > 3 > > 4 > > 5 > > 23 > > I want to join these tables where the columns Sample and Plot are the same. > > Currently trying: > > df<- right_join(df, df1, by = c(?Sample?, "Plot")) > > I am working with a much larger dataset, but it will cut off the data > starting at Sample 3 instead of joining the tables while retaining the > information from df. Any ideas how I could join them this way? > > > Esthi > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.