2014-09-05 38 views
-1

我有一個問題將日期變量從因子轉換爲日期格式。 這是我在開頭:as.Date不斷返回不適用

data.frame: 1629 obs. of 12 variables: 
$ date : Factor w/ 1629 levels "01/02/2008","01/02/2010",..: 90 145 308 364 421 475 531 698 756 808 ... 

我試圖因子值字符轉換,然後到時間,但仍然沒有運氣 這些都是我一直在使用的語法:

research2$date <- as.character(research2$date) 

research2$date <- as.Date(research2$date, "$d/$m/$Y") 

和得到的回報是:

data.frame: 1629 obs. of 12 variables: 
$ date : Date, format: NA NA NA NA ... 

我也試圖改變區域設置,但仍然沒有運氣。

回答

1

您需要在格式字符串中使用%而不是$。

research2$date <- as.Date(research2$date, "%d/%m/%Y")