Thanks for all the help I received from a simple read.
I am not happy with my R cycles when I deal with only one data.frame file because I write again and again the name of the data framework that inflates my R code.
Here is a stupid example:
x<- rep(NA,10) y <- 1:10 dat <- data.frame(x,y) for(i in 2:nrow(dat)){ dat$x[i] <- dat$y[i] + dat$y[i-1] }
So I want to get rid of dat$ -bit. External loops can be done using within() , but I'm not quite sure if you really can do this with R. I tried this:
remove(x,y)
The result is as follows:
xyi 1 NA 1 10 2 3 2 10 3 5 3 10 4 7 4 10 5 9 5 10 6 11 6 10 7 13 7 10 8 15 8 10 9 17 9 10 10 19 10 10
So the loop really worked, but just a new magic column.
Does anyone know (1) what is happening here and (2) how to handle such types of loops elegantly (a more complex example of wrapping within() around a loop, including several if() and failed btw calculations?
Thank you very much! SKR
source share