[Solved] How to add a variable in a data frame using another variable for indices?
You need joins, and something like tidyr::fill: library(dplyr) library(tidyr) x %>% mutate(slopezz = slopezz[1:n()]) %>% right_join(veh, by = c(‘psi’ = ‘Tim’)) %>% fill(slopezz, .direction = ‘up’) # psi slopezz # 1 169.7 -2.1920 # 2 169.8 -2.1920 # 3 169.9 -2.1920 # 4 170.0 -2.1920 # 5 170.1 -2.1920 # 6 170.2 -2.1920 # . … Read more