How to delete an entire row if it is all 0's in R -
if have data frame so
4 6 6 0 4 5 0 0 6 5 0 4 4 4
but lot bigger, command can write delete row 0's, such row 4 in example.
in end this
4 6 6 0 4 5 6 5 0 4 4 4
thanks!
something this?
df[apply(df[, sapply(df, is.numeric)], 1, function(x) !all(x==0)), ]
or
df[rowsums(abs(df[, sapply(df, is.numeric)])) != 0, ]
example:
> df <- data.frame(x=c(1, 2, 0), y=c(0, 1, 0), z=letters[1:3]) > df x y z 1 1 0 2 2 1 b 3 0 0 c > df[rowsums(abs(df[, sapply(df, is.numeric)])) != 0, ] x y z 1 1 0 2 2 1 b
Comments
Post a Comment