Skip to content
Prev 201490 / 398506 Next

linear regression on groups of consecutive rows of a matrix

Perhaps along these lines:
1st  #need to decide what your group width is , so the second number  
inside the extraction call will be that number minus 1:

for (x in seq(1:1000, by=6) {
     temp <- na,omit( shp[x:(x+5), ] )  # Need the parens in x:(x+5)
     lm( formula, data=temp)
    }

Or depending on what you actually meant:

for (x in seq(1:1000, by=5) {
     temp <-  shp[ x:(x+4), which(!is.na(shp[x:x+4, ]))]
     lm( formula, data=temp)
    }

But I do feel compelled to ask: Do you really get meaningful  
information from lm applied to 5 cases? Especially when the predictors  
used may not be the same from subset to subset???