I have data.table G with columns A, B, C:
code below counts NA values in the column A:
G[is.na(A), .N]
But when I try to use Column index(For column A index = 1) - I see no result:
G[is.na(.SD), .N, .SDcols = 1]
How can I fix this problem correctly?
We can get the count from the 'j' itself.
G[, sum(is.na(.SD)), .SDcols = 1]
and if there are multiple columns, loop through the columns and get the sum
of NA elements
G[, lapply(.SD, function(x) sum(is.na(x))), .SDcols = 1:2]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With