0

I want to join two dataframes (x and y) which have a shared column (time, that they should be also be ordered by) and keep all the values from both dataframes in the resulting dataframe (z). To do this is easy enough with dplyr::full_join. However, instead of the NAs produced through the join, I would like to recycle row values, until the next value is contained, in one of the columns, (in this example, the month column in the resulting z2 dataframe).

library(dplyr)

set.seed(19)

# dummy data
x <- data.frame(time = rnorm(length(month.name))^2, month = month.name)
y <- data.frame(time = rnorm(length(LETTERS))^2, letters = LETTERS)

# join
z <- dplyr::full_join(x, y, by = "time") %>% dplyr::arrange(time)

How would I achieve this, preferably within dplyr/tidyverse?

eartoolbox
  • 327
  • 2
  • 10

0 Answers0