这是我的数据集概述。 我想将R中的month(format = character)转换为formate:date
I have tried as.Date() as.Date(df$month, "%Y-%m")
but it fails to convert.
I have used anytime() and as.POSIXct()
我要转换日期的原因是我需要通过变量rime与其他数据集进行left_join。
crime_type month n rate
<chr> <chr> <int> <dbl>
1 Bicycle theft 2017-04 33 NA
2 Bicycle theft 2017-05 32 1.03
3 Bicycle theft 2017-06 36 0.889
4 Bicycle theft 2017-07 39 0.923
5 Bicycle theft 2017-08 52 0.75
6 Bicycle theft 2017-09 36 1.44
另一个数据集在这里
ym unemploy_rate
<chr> <dbl>
1 2017-1 4.6
2 2017-2 4.6
3 2017-3 4.5
4 2017-4 4.4
5 2017-5 4.4
6 2017-6 4.3
7 2017-7 4.3
We can
paste
with a day and useas.Date
Or another option is to convert to
yearmon
class and then useas.Date