我有一個數據框,其中一列中的數據當前是「字符」,我需要將其更改爲「日期」,但日期是混合格式,所以我不能只使用as.Date()。列中也有空行。這裏是一個樣本的數據如何在同一列中標準化混合日期格式
> head(FarmersMkt$StartDate,n = 50)
[1] "June " "January " "05/01/2013 " "July " "06/17/2013 " "05/04/2013 " "" "06/27/2013 "
[9] "June " "" "06/29/2013 " "06/06/2013 " "" "May " "" ""
[17] "05/11/2013 " "01/01/2013 " "" "June " "June " "06/06/2013 " "" ""
[25] "" "04/20/2013 " "" "" "05/11/2013 " "" "01/01/2013 " "01/01/2013 "
[33] "06/06/2013 " "May " "06/23/2013 " "01/01/2013 " "June 17, 2012 " "June " "" ""
[41] "06/06/2013 " "" "May " "" "" "" "04/20/2013 " "01/01/2013 "
[49] "07/13/2013 " ""
所有的年份應該是2013年,日期可以是虛擬數據。如何將此列中的數據轉換爲日期格式?
你想「六月」轉換爲什麼? – josliber
堆棧溢出的好問題不僅指定了您擁有的數據,還指定了預期的輸出,因此如果出現這種情況,您應該編輯問題以說明只需要月/年。是從2013年的所有日期?否則,你如何知道「六月」中輸入的年份? – josliber
我們可以使用虛擬日期和年份,因爲我只需要一個月,但我需要它與其他格式相同格式06/06/2013 –