- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2022 11:03 AM
Databricks Community
New to Databricks and work in R code. I have a data from with a date field that is a chr string and need to convert to a date field. Tried the standard as.Date(x, format = "%Y-%m-%d") , then tried the dplyr::mutate function and that errored out to. So how does one convert chr date strings to a Date string.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 02:16 AM
you can use universal sql syntax with R dataframes
df <- read.df(path = "/tmp/df.avro", source = "com.databricks.spark.avro")
createOrReplaceTempView(dfView, "df")
species <- sql("SELECT TO_DATE(string_date, 'dd/MM/yy') FROM dfView")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 02:16 AM
you can use universal sql syntax with R dataframes
df <- read.df(path = "/tmp/df.avro", source = "com.databricks.spark.avro")
createOrReplaceTempView(dfView, "df")
species <- sql("SELECT TO_DATE(string_date, 'dd/MM/yy') FROM dfView")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 11:32 AM
Well that was certainly helpful - thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 06:34 AM
Based upon the initial response I went with:
my_data.frame <- my_data.frame %>%
mutate(date = to_date(data.frame_variable, "yyyy-mm-dd"))
![](/skins/images/B38AF44D4BD6CE643D2A527BE673CCF6/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/B38AF44D4BD6CE643D2A527BE673CCF6/responsive_peak/images/icon_anonymous_message.png)