Joining different length data frames with different columns in R
Seems like you're just looking for a simple left_join. This can be done via dplyr with
left_join(df2, df1)
which will only return rows where df2 and df1 match in the timestamp column. (This drops all of the extra observations in df1).
A base R implementation is:
merge(x = df2, y = df1, by = "timestamp", all.x = TRUE)
Merge and fill different length data in R
using merge
with parameter all
set to TRUE
:
tibble1 <- read.table(text="
x y
a 5
b 10
c 15
d 25",header=TRUE,stringsAsFactors=FALSE)
tibble2 <- read.table(text="
x z
a 7
c 23
d 20",header=TRUE,stringsAsFactors=FALSE)
merge(tibble1,tibble2,all=TRUE)
x y z
1 a 5 7
2 b 10 NA
3 c 15 23
4 d 25 20
Or dplyr::full_join(tibble1,tibble2)
for the same effect
Related Topics
Adding Some Space Between the X-Axis and the Bars, in Ggplot
R: How to Check If All Columns in a Data.Frame Are the Same
How to Find the Closest Date to a Given Date
Remove Rows With All or Some Nas (Missing Values) in Data.Frame
How to Select the Rows With Maximum Values in Each Group With Dplyr
How to Use R'S Ellipsis Feature When Writing Your Own Function
Is There a Dplyr Equivalent to Data.Table::Rleid
How to Do Vlookup and Fill Down (Like in Excel) in R
Categorize Numeric Variable into Group/ Bins/ Breaks
Error in Confusionmatrix the Data and Reference Factors Must Have the Same Number of Levels
Create Counter Within Consecutive Runs of Values
Column Name Changes in R for Loop for Defined Data Frame
Calculate Group Mean, Sum, or Other Summary Stats. and Assign Column to Original Data
Summarizing Multiple Columns With Dplyr
Show Percent % Instead of Counts in Charts of Categorical Variables
Run R Script from Command Line
How to Succinctly Write a Formula With Many Variables from a Data Frame