I'm trying to do a simple for loop on multiple data frames and save the output (from all data frames) to one list.
Here is example data:
# Two example data frames (variables x and y)
a <- data.frame(x=rnorm(1:100, 10, 1), y=1:100)
b <- data.frame(x=rnorm(1:100, 500, 50), y=1:100)
# Merging data frames to a list, which we aim to loop through
data_frame_list <- list(a, b)
# Desired list
new_list <- list()
# The loop
# I want two simple values from each data frame (value1 and value2)
for(i in data_frame_list) {
for(j in 1:5) {
value1 = i[j,1]
value2 = i[j,2]
new_list[i] <- cbind(value1, value2)
}
}
So from each data frame i want value1 and value 2 for all the j values (1 to 5). I'd like to have all the extracted data in a list (new_list).
Thanks for help