I am working on a project in R and, coming from Stata, am having a hard time adjusting to how for loops work. When I run this code below, I get exactly what I want. I create a new dataframe "states_1" out of an already existing dataframe "data_frame1."
states_1 <- data_frame1[["interest_over_time"]]
states_1 <- states_1[-c(1:66),]
states_1 = dcast(states_1, date ~ keyword + geo, value.var = "hits")
However, I have almost 15 dataframes and this is a shared project, so I would rather not have to repeat this for every dataframe and use a for loop instead. However, the code below tells me that I am trying to treat a function like a dataframe. Would appreciate help with how to proceed
for(i in 1:13) {
states[i] <- data_frame[i][["interest_over_time"]]
states[i] <- states[i][-c(1:66),]
states[i] = dcast(states[i], date ~ keyword + geo, value.var = "hits")
}