I'm learning how data tables work and I'm trying to use grep()
on two columns (id1
and id2
) to delete rows that don't return TRUE
.
I know I have to use the function lapply()
but it always returns the followed error :
argument 'pattern' has length > 1 and only the first element will be used
I tried this (and I know it's wrong) :
DT[, lapply(.SD, grepl(id1, id2)), by= id]
The data I'm working on :
structure(list(id = c(52L, 52L, 52L, 52L, 54L, 54L, 84L, 84L,
87L, 87L, 129L, 129L, 130L, 130L, 130L), id1 = c("8113H187",
"3505H6", "3505H6", "3505H6", "3505H6", "3505H6", "3505H6", "3505H6",
"8113H187", "8113H187", "3505H6", "3505H6", "3505H6", "3505H6",
"3505H6"), id2 = c("3505H6856", "3505H6856", "3505H6856", "3505H6856",
"3505H67158", "3505H67158", "3505H63188", "3505H63188", "3505H64691",
"3505H64691", "3505H664133", "3505H664133", "3505H658134", "3505H658134",
"3505H658134")), .Names = c("id", "id1", "id2"), row.names = c(NA,
-15L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x00000000064f0788>)