I wrote a function that reads in data and applys some transformation. Now I would like to write a for loop to get the different files I want and assign them as dataframes to a list. Unfortunately, I do not understand the syntax of the procedure I guess.
> list_of_df <- {}
> for (i in 10:20) {
> df <- read_my_data(i)
> list_of_df[[i]] <- df
> }
my function to read in the data works perfectly fine and returns a dataframe. i is used as the argument in the function to identify the correct data. I struggle to attach the dataframes that result from my function to the empty list at the correct place.
Would be great if you could tell me how that mechanism is supposed to work...
the result should be like:
list_of_df
$10
....
$11
....
....
$20
I know that it works for vectors like:
> empty_vector <- vector()
> for (i in 1:10) {
> empty_vector[i] <- i
> }
but if I do it from higher values than 1, I get NAS and I am also unable to transfer it to dataframes and lists...
Thank you for your help