[R] store results in loop

Nico Gutierrez nico.gutierrezo at gmail.com
Tue Sep 22 11:36:09 CEST 2015


Hi All,

very rusty in R.. my results get overwritten when try to store within the
loop. This my code:
ListS=unique(data$Spec)
Stat<- numeric(0)

for(i in 5){

SS=subset(data,data$Spec==ListS[i])
maxC<- which.max(SS$Cc)
smoothC=mean(SS$Cc[maxC + c(-2:2)])
currC=tail(SS,1)$Cc
Index=currC/smoothC

Stat[i]=c(Stat, Index[i])
}
Stat

This is what I get:

[1] NA NA NA NA NA


I am obviously not indexing well here.


Thanks!!!

N

	[[alternative HTML version deleted]]



More information about the R-help mailing list