I have the following dataframe in R. I have created a new column called 'Average' which takes the mean of the first three columns in my dataframe, but I would like to do it using column indexes (e.g column 2,3,4) as opposed to the column name. Is there a way to do that?
library(tidyverse)
data <- structure(list(Model = c("Adjusted Compnents Model", "ARIMA",
"STIF Model"), `2021-11-30` = c(0.2, 0.1, 0.3), `2021-12-31` = c(0.2,
0.3, 0), `2022-01-31` = c(0.2, 0.5, 0.3), `2022-02-28` = c(0.1,
0.3, 0.1), `2022-03-31` = c(0.1, 0.2, 0.1), `2022-04-30` = c(0.2,
0.1, 0.1)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-3L))
data %>%
mutate(Average = mean(`2021-11-30`:`2022-01-31`), .after = 4)