[R] for 1:length and removing rows

Markus Mühlbacher muehliman at yahoo.com
Thu Sep 4 17:33:06 CEST 2008

Hello everyone,

I have a problem using a for-loop to go through a matrix. I want to remove all rows with a sum of 0.
What I do is basically:

for(i in 1:length(data))
   if(sum(add(data[i,]) == 0)
      data <- data[-i,]

I get a error message: "Error in `[.data.frame`(data, i) : undefined columns selected", because the length is reduced when removing in the if-clause.

How do I make this?

Best wishes,

More information about the R-help mailing list