Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- library(dplyr)
- library(magrittr)
- dt = fread('No, A, B, C, D, E, F, G
- 1, 8, 9, 0, 5, 7, 1, 1
- 2, 4, 0, 6, 1, 7, 0, 3
- 3, 0, 1, 0, 6, 0, 0, 0
- 4, 5, 3, 2, 7, 0, 2, 0
- 5, 5, 6, 2, 0, 3, 1, 0
- 6, 0, 3, 2, 1, 6, 7, 1
- ')
- f = function(x){ x[x<5] = 0; x}
- dt %<>% mutate_each(funs(f), -No)
- dt
- # No A B C D E F G
- # 1: 1 8 9 0 5 7 0 0
- # 2: 2 0 0 6 0 7 0 0
- # 3: 3 0 0 0 6 0 0 0
- # 4: 4 5 0 0 7 0 0 0
- # 5: 5 5 6 0 0 0 0 0
- # 6: 6 0 0 0 0 6 7 0
- ## 就回到原本的案例了
Advertisement
Add Comment
Please, Sign In to add comment