I read my data frame and stored it in a variable. Then I created an empty list. I created a loop which goes through the columns and makes a dataframe from the select() function and assigns it to the next position in the list. However, that is not what is happening, only the columns are being stored in the list.
here is my code:
library(tidyverse)
data = read_csv('hubbard_data.csv')
columns = colnames(data)
#make date and time correct
data$TIMESTAMP_START = strptime(data$TIMESTAMP_START,"%Y%m%d%H%M")
data$TIMESTAMP_END = strptime(data$TIMESTAMP_END,"%Y%m%d%H%M")
dfs = list() #List of data frames
it = 1 #Iterator
while(it <= length(columns)){
dfs[it] <- data %>% select(columns[it],LE)
it = it + 1
}
I did a little further analysis and found this:
temp1 <- data %>% select(columns[1],LE)
dfs[1] <- data %>% select(columns[1],LE)
temp1 is a data.frame but dfs[1] is not. Why?