I'm trying to convert a character column to a date column by using the as.Date
function. It works when I enter as.Date(data$colname)
. However, when I enter as.Date(data[,"colname"])
is returns
do not know how to convert 'data[,"colname"]' to class “Date”
- Why does it not work for the second option?
- How can I change the second option so that it works?
At the end I want to use the as.Date
in a function with the column name as an argument. In that way I don't see how I can use $
.
Thanks!
Sample of my data:
structure(list(colname = structure(c(1014036051, 1034089765,
1237297478, 1260283949, 1274454601, 1580486457.445, 1581671766.241,
1401445496, 1279550892, 1173094955), tzone = "UTC", class = c("POSIXct",
"POSIXt"))), row.names = c(NA, -10L), class = c("tbl_df", "tbl",
"data.frame"))