r - Does dplyr or plyr have a remainder function? -
does dplyr or plyr have remainder function?
let have series of mode (1-25)
for example dataset main
idc3 = c("23|24") column0|column1|column2|column3|mode1|mode2|mode3 4 | 83 | 23 | 863 | 85 | 86 | 45 53 | 26 | 9 | 153 | 23 | 34 | 85 33 | 66 | 91 | 693 | 95 | 23 | 74 6 | 87 | 27 | 863 | 47 | 56 | 52 57 | 27 | 9 | 153 | 78 | 38 | 64 37 | 67 | 97 | 693 | 34 | 86 | 24 cut <- main[unique(grep(paste(idc3), main$mode1)), ] cut2 <- main[unique(grep(paste(idc3), main$mode2)), ] cut3 <- main[unique(grep(paste(idc3), main$mode3)), ] column0|column1|column2|column3|mode1|mode2|mode3 53 | 26 | 9 | 153 | 23 | 34 | 85 33 | 66 | 91 | 693 | 95 | 23 | 74 37 | 67 | 97 | 693 | 34 | 86 | 24 what if remainder dataset
column0|column1|column2|column3|mode|mode2|mode3 4 | 83 | 23 | 863 | 85 | 86 | 45 6 | 87 | 27 | 863 | 47 | 56 | 52 57 | 27 | 9 | 153 | 78 | 38 | 64 is there way this? thanks
instead of creating 3 separate cuts, can create index 1 function call. able choose matched columns or opposite needed:
idc3 = c(23,24) indx <- as.logical(rowsums(sapply(df[,5:7], `%in%`, idc3))) df[indx,] # column0 column1 column2 column3 mode1 mode2 mode3 # 2 53 26 9 153 23 34 85 # 3 33 66 91 693 95 23 74 # 6 37 67 97 693 34 86 24 df[!indx,] # column0 column1 column2 column3 mode1 mode2 mode3 # 1 4 83 23 863 85 86 45 # 4 6 87 27 863 47 56 52 # 5 57 27 9 153 78 38 64
Comments
Post a Comment