Guest User

Untitled

a guest
Nov 16th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. index <- seq(1, 10, 1)
  2. blockID <- c(100, 120, 132, 133, 201, 207, 210, 238, 240, 256)
  3. df <- as.data.frame(cbind(index, blockID))
  4.  
  5. blocklist <- c(100, 120, 130, 150, 201, 205, 210, 238, 240, 256)
  6.  
  7. df2 <- df %>% mutate(blockmatch = ifelse(blockID %in% blocklist, blockID, ifelse(match.closest(blockID, blocklist, tolerance = Inf), "missing")))
  8.  
  9. df %>%
  10. rowwise() %>%
  11. mutate(
  12. new = blocklist[order(abs(blockID - blocklist))][1]
  13. )
  14.  
  15. # A tibble: 10 x 3
  16. index blockID new
  17. <dbl> <dbl> <dbl>
  18. 1 1.00 100 100
  19. 2 2.00 120 120
  20. 3 3.00 132 130
  21. 4 4.00 133 130
  22. 5 5.00 201 201
  23. 6 6.00 207 205
  24. 7 7.00 210 210
  25. 8 8.00 238 238
  26. 9 9.00 240 240
  27. 10 10.0 256 256
Add Comment
Please, Sign In to add comment