I have 13 datasets that are in .XPT format called data2010, data2011, data2012.. data2022. These are the BRFSS datasets from the CDC website. I have been trying to add three new columns to each of my dataframes called TREAT, POST and YEAR and initialise them to some value. This is a short snippet of my code
library(dplyr)
datasets <- list(data2010, data2011, data2012, data2013, data2014, data2015,
data2016, data2017, data2018, data2019, data2020, data2021, data2022)
for(i in 1:length(datasets)) {
datasets[[i]] <- datasets[[i]] %>%
mutate(TREAT = 0, POST = 0, YEAR = i + 2009)
}
I have ran this multiple times to no avail. I can see on the environment pane in RStudio that the number of columns do not increase and when I use the console to check (by running data2017$POST
, I get the following response
NULL
Warning message:
Unknown or uninitialised column: `POST`.
Does anyone know what I am doing wrong?