[英]How to format the date in r
I have a date format like this:我有这样的日期格式:
head(ergo_bike)
# A tibble: 6 × 8
hour date...2 time_bike distance calories power `Participant Code` date...8
<dbl> <dttm> <dbl> <dbl> <dbl> <dbl> <chr> <dttm>
1 12 2022-04-12 00:00:00 2 0 0 0.00613 AE1_01 2022-04-12 00:00:00
2 13 2022-04-12 00:00:00 2 0 0 0.00580 AE1_01 2022-04-12 00:00:00
3 14 2022-04-12 00:00:00 1 0 0 0.00258 AE1_01 2022-04-12 00:00:00
4 14 2022-04-13 00:00:00 2 0 0 0.00714 AE1_01 2022-04-13 00:00:00
5 14 2022-03-11 00:00:00 3 0.746 11.2 0.00868 AE1_02 2022-03-11 00:00:00
6 15 2022-03-11 00:00:00 1 0.250 3.75 0.00274 AE1_02 2022-03-11 00:00:00
structure(list(hour = c(12, 13, 14, 14, 14, 15), date...2 = structure(c(1649721600,
1649721600, 1649721600, 1649808000, 1646956800, 1646956800), tzone = "UTC", class = c("POSIXct",
"POSIXt")), time_bike = c(2, 2, 1, 2, 3, 1), distance = c(0,
0, 0, 0, 0.7463732, 0.24986416), calories = c(0, 0, 0, 0, 11.195598,
3.7479625), power = c(0.006130556, 0.005802778, 0.002577778,
0.007138889, 0.008683333, 0.002738889), `Participant Code` = c("AE1_01",
"AE1_01", "AE1_01", "AE1_01", "AE1_02", "AE1_02"), date...8 = structure(c(1649721600,
1649721600, 1649721600, 1649808000, 1646956800, 1646956800), tzone = "UTC", class = c("POSIXct",
"POSIXt"))), row.names = c(NA, -6L), class = c("tbl_df", "tbl",
"data.frame"))
How can I format the date into the this form: yyyy-mm-dd (I don't want the time included)如何将日期格式化为以下形式:yyyy-mm-dd(我不希望包含时间)
You can use您可以使用
as.Date()
so that will make it:这样就可以了:
as.Date(ergo_bike$date...2, "%Y-%m-%d")
You can see the syntax on https://www.statmethods.net/input/dates.html您可以在https 上查看语法://www.statmethods.net/input/dates.html
I believe you can use "yourdata<-as.Date(your_data, "%Y%m/%d/") See this for more info on as.Date我相信您可以使用 "yourdata<-as.Date(your_data, "%Y%m/%d/") 有关 as.Date 的更多信息,请参阅此内容
Hope it helps希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.