celestialgod

move to left if number is lees than 5

Sep 14th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.54 KB | None | 0 0
  1. library(data.table)
  2. library(dplyr)
  3. library(magrittr)
  4. dt = fread('No, A, B, C, D, E, F, G
  5. 1, 8, 9, 0, 5, 7, 1, 1
  6. 2, 4, 0, 6, 1, 7, 0, 3
  7. 3, 0, 1, 0, 6, 0, 0, 0
  8. 4, 5, 3, 2, 7, 0, 2, 0
  9. 5, 5, 6, 2, 0, 3, 1, 0
  10. 6, 0, 3, 2, 1, 6, 7, 1
  11. ')
  12. f = function(x){ x[x<5] = 0; x}
  13. dt %<>% mutate_each(funs(f), -No)
  14. dt
  15. #    No  A  B  C  D  E  F  G
  16. # 1:  1  8  9  0  5  7  0  0
  17. # 2:  2  0  0  6  0  7  0  0
  18. # 3:  3  0  0  0  6  0  0  0
  19. # 4:  4  5  0  0  7  0  0  0
  20. # 5:  5  5  6  0  0  0  0  0
  21. # 6:  6  0  0  0  0  6  7  0
  22. ## 就回到原本的案例了
Advertisement
Add Comment
Please, Sign In to add comment