I have a list called result2 that contains 366 dataframes and I want to subset each dataframe by the variable names ("time","summary","precipProbability","apparentTemperature","humidity","windSpeed"). I have been able to subset them individually (below) however whenever I have tried to use a for loop or the apply family of functions I have failed.
result2[[1]] <- data.frame(result2[[1]])[, c("time","summary","precipProbability","apparentTemperature","humidity","windSpeed")]
result2[[2]] <- data.frame(result2[[2]])[, c("time","summary","precipProbability","apparentTemperature","humidity","windSpeed")]
Here are my attempts at a for loop which runs but my code gets an error and the errors says that the number of items to replace is not a multiple of replacement length
weather_variables <- c("time","summary","precipProbability","apparentTemperature","humidity","windSpeed")
for (i in 1:366){
result2[[i]] <- data.frame(result2[[i]])[, weather_variables]
}
Thanks !