Reputation: 924
I have a raster stack s
with 744 layers. Of these, 744, I need to make new stack S1
with layers 18 to 24 (i.e. 6 layers from 18) and then next 6 layers at a gap of 24 from 18 (i.e. 42 to 48). So I need to keep picking 6 layers at gap of 24 till I reach the end of the stack. So what I have done is follows:
x<-data.frame(seq(18, 744, by = 24))
x$v2<-seq(24, 744, by = 24)
S1<-stack(s[[x[1,1]:x[1,2]]])
for(i in 2:nrow(x)){
S1<-stack(S1,s[[x[i,1]:x[i,2]]])
}
However, I would like to know a if there is a cleaner and better way to do this.
Upvotes: 0
Views: 203
Reputation: 47536
You can do
i <- rep(18:24, 31) + rep(0:30, each=7) * 24
S2 <- S1[[i]]
Upvotes: 2