1
嗨我正在處理數據集,如下所示。我試圖在日期列上運行dmy函數,並返回日期,否則返回數據中存在的任何內容。我如何獲得日期輸出作爲日期而不是一些長數字。謝謝將日期格式不是日期格式的輸出格式化爲日期對象
> dataF[1:5, 1:5]
ID_NO DTTM DATE_YEAR TERM ISSUE_DT
1 1478 4-Sep-06 2006 27 2006-09-14
2 5032 27-Oct-06 2006 36 2006-11-02
3 3192 8-Jan-07 2007 10 2007-01-08
4 3978 28-Jan-07 2007 20 2007-01-31
5 6617 5-Jan-07 2007 10 2007-01-05
>
> lapply(dataF[1:5, 1:5], function(x){ifelse(is.na(dmy(x)), x, dmy(x))})
$ID_NO
[1] "1478" "5032" "3192" "3978" "6617"
$DTTM
[1] 1157328000 1161907200 1168214400 1169942400 1167955200
$DATE_YEAR
[1] 2006 2006 2007 2007 2007
$TERM
[1] 27 36 10 20 10
$ISSUE_DT
[1] 1158192000 1162425600 1168214400 1170201600 1167955200