日期當前是 yyyy-mm-dd,但我希望它為 mm/dd/yyyy。
我嘗試了各種方法,這些方法要么完全沒有發生,要么出現錯誤,例如:
警告訊息:計算時出現問題date = lubridate::mdy(date)。? 所有格式決議失敗。未找到格式。
錯誤mutate():!計算時出現問題date = format(date, "%m/%d/%Y")。由錯誤引起format.default():!無效的“修剪”引數回溯:
- 質量 %>% 變異(日期 = 格式(日期,“%m/%d/%Y”))
- base::format.default(日期,“%m/%d/%Y”)
我該如何解決?
library(dplyr)
library(lubridate)
mass = read.csv('https://raw.githubusercontent.com/bandcar/Examples/main/mass_killing_incidents_public.csv')
mass2 = mass
mass2$date = format(mass$date, format = "%m/%d/%Y")
mass2 = mass %>%
mutate(date = lubridate::mdy(date),
date = strftime(date, "%m/%d/%Y"))
mass2 = mass %>%
mutate(date = format(date, '%m/%d/%Y'))
uj5u.com熱心網友回復:
我們可以做
library(dplyr)
library(lubridate)
mass %>%
mutate(date = lubridate::ymd(date), date = strftime(date, "%m/%d/%Y"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/515683.html
標籤:r日期dplyr润滑
