I would like to read and store data using a forloop, I see that most of the code is working, I could generate the file names with the forloop however the data is not being stored and the error is occured.
Here is a brief guide about iteration and storing the results
# overwriting values
for (i in 1:3) {
w <- i * i
}
w
# collating values when they are primitives
x <- numeric(0)
for (i in 1:3) {
x <- c(x, i * i)
}
x
# collating values when they are not primitives
y <- list()
for (i in 1:3) {
y <- append(y, list(list(
letters[i],
LETTERS[i * i], i * i
)))
}
y
str(y)
# same but functional approach
z <- lapply(1:3, function(i) {
list(
letters[i],
LETTERS[i * i], i * i
)
})
str(z)