R: group by list of column names -
i have data table result join between 2 other tables (a, b)
joinedtable = a[b, on = columnname]
i want count frequency of rows combinations based con column names can vary (all, 1 on somewhere in middle). problem works being hardcoded not variable:
joinedtable[, list(freq =.n), = list( column_a, column_b, ...)] # works # what's next doesn't columns = names(joinedtable)[-which(names(joinedtable) %in% c('column_f', 'column_g',...))] joinedtable[, list(freq =.n), = as.list(columns)] # doesn't work
if try dynamic error:
error in `[.data.table`(joinedtable, , list(freq = .n), = list(outcolumns)) : items in 'by' or 'keyby' list length (13). each must same length rows in x or number of rows returned (23).
how should works?
already found answer , it's pretty simple , silly error:
this line
joinedtable[, list(freq =.n), = as.list(columns)]
needs changed to:
joinedtable[, list(freq =.n), = columns]
since columns array.
Comments
Post a Comment