I am able to Standardizing each observation for the variable "len" using the mean and standard deviation calculated from only prior observations. However, I am uable to attach it as a column to my dataframe 'tg'. Can you please help me with this.
This is my data and the code below
tg<-structure(list(len = c(4.2, 11.5, 7.3, 5.8, 6.4, 10, 11.2, 11.2,
5.2, 7, 16.5, 16.5, 15.2, 17.3, 22.5, 17.3, 13.6, 14.5, 18.8,
15.5), supp = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("OJ",
"VC"), class = "factor"), dose = c(0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
a<-for (i in 1:20) print((a=(tg$len[i]-mean(tg$len[1:i]))/sd(tg$len[1:i])))
a
How do I merge 'a' to dataframe 'tg'?