0

I have a date variable in my data frame, but skim(df) will output the date variable as character variable. How do I specify in the code that it needs to recognize the date, and output range of the date variable?

df = data.frame(date = c( "2/3/2021","2/4/2022","2/5/2019"), x= c(1,4,5), y = c(1909,1902,19092))

Also, is the only way to correct the variable types so skim() recognize the correct variable type is by as.factor(df$column) or as.numeric(df$column2) before applying the skim() or skim_with()?

Thank you.

merry123
  • 103
  • 5
  • 1
    The original column is character type, thus it picks as character class. You may need `df$date <- as.Date(df$date, "%m/%d/%Y")` – akrun Jul 27 '22 at 18:23
  • 2
    There is an option with `get_skimmers` for other datatypes to be added as in [skimr vignette](https://cran.r-project.org/web/packages/skimr/vignettes/skimr.html), but i think transforming the column type before applying would be better – akrun Jul 27 '22 at 18:46
  • Is there a way to automate the conversion process so I don't have to write multiple lines of as.Date to every needed column in the data frames? – merry123 Jul 28 '22 at 14:28
  • 1
    you may check https://stackoverflow.com/questions/38135764/readr-importing-date-column-in-csv – akrun Jul 28 '22 at 16:43
  • You would want to use as.Data() or a lubridate function, basically before skimming if you can generate a vector of the names you can lapply() and not have a long list of as.Data(). – Elin Aug 09 '22 at 02:46

0 Answers0