I have a large dataframe and need to remove a few rows from it as rowSums
shows these to be 0 and thus impacting my downstream analysis. I've seen that you can do df[rowSums(df[, -1])>0, ]
to achieve this, but I get an error stating that "x must be numeric" as both the first and last columns are not numeric. Any ideas of how to get around this?
Asked
Active
Viewed 25 times
-1

Maho
- 59
- 1
- 7
1 Answers
1
We need to remove the first and last columns by indexing
i1 <- sapply(df, is.numeric) # // get a logical index for numeric columns
df[rowSums(df[i1]) > 0,]

akrun
- 874,273
- 37
- 540
- 662
-
brilliant, thanks! – Maho Feb 08 '21 at 17:13