I have multiple data frames in my R environment eg. data1,data2,data3. The first column is a date column having header "X"(same header in all data frames)but its class is showing as character. So i want to use as.Date() function on the first column of all the dataframes in my environment.
data1$X <- as.Date(data1$X)
The above line works fine for one data frame. But I Want to use a for loop for all the data frames. I have a list of the names of all the data frames.
list <- c("data1", "data2", "data3")
I tried doing the following
for (i in list) {
i$x <- as.Date(i$x)
}
which doesn't work.
Any help will be appreciated.
list
is a character vector. So ati$x
you try something like"data1"$x
(for example). BTW: "doesn't work" is not enough information, certainly you got an error message. Please put the error message in your question! – jogo