Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- index <- seq(1, 10, 1)
- blockID <- c(100, 120, 132, 133, 201, 207, 210, 238, 240, 256)
- df <- as.data.frame(cbind(index, blockID))
- blocklist <- c(100, 120, 130, 150, 201, 205, 210, 238, 240, 256)
- df2 <- df %>% mutate(blockmatch = ifelse(blockID %in% blocklist, blockID, ifelse(match.closest(blockID, blocklist, tolerance = Inf), "missing")))
- df %>%
- rowwise() %>%
- mutate(
- new = blocklist[order(abs(blockID - blocklist))][1]
- )
- # A tibble: 10 x 3
- index blockID new
- <dbl> <dbl> <dbl>
- 1 1.00 100 100
- 2 2.00 120 120
- 3 3.00 132 130
- 4 4.00 133 130
- 5 5.00 201 201
- 6 6.00 207 205
- 7 7.00 210 210
- 8 8.00 238 238
- 9 9.00 240 240
- 10 10.0 256 256
Add Comment
Please, Sign In to add comment