[R] Joining data frames

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Tue Jun 29 17:43:17 CEST 2021


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 using 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 using 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]]



More information about the R-help mailing list