2014-01-16 1 views
1

다음 코드를 사용하여 날짜 열을 올바른 형식으로 가져 오려고했지만 모든 날짜가 "NA"로 반환됩니다.R로 as.Date를 사용하여 날짜로 변환하고 일련의 "NA"를 가져옴

setwd("C:\\Users\\user\\Documents\\Files\\a") 
data <- read.csv("file1.csv") 

data$Date <- as.Date(data$Date, format = "d%/m%/Y%") 

편집 : 날짜 값을 다음과 같이하십시오 ?as.Date 문서에서 2009년 11월 9일

+1

당신은 우리에게 '날짜'열 값을 표시 할 수 있습니다. 아마도 여기서 지정한 형식이 일치하지 않습니다. – RUser

+3

'format = "% d/% m/% Y"'시도해보십시오. – Roland

답변

3

:

If the date string does not specify the date completely, the returned answer may be system-specific. The most common behaviour is to assume that a missing year, month or day is the current one. If it specifies a date incorrectly, reliable implementations will give an error and the date is reported as ‘NA’. Unfortunately some common implementations (such as ‘glibc’) are unreliable and guess at the intended meaning.

data$Date <- as.Date(data$Date, format = "%d/%m/%Y") 
+0

솔루션 위로 틱 마크를 선택하십시오 - 도움이된다면 이것을 anwser로 지정하십시오 – RUser

0

당신은 패키지 lubridate으로 날짜를 변환 시도 할 수

library(lubridate) 
date <- parse_date_time(x = date, 
       orders = c("d m y", "d B Y", "mdy"), 
       locale = "eng") 

당신이 날짜로 원하는 형식으로 지정할 수 있습니다 후 :

character_date <- as.character(as.Date(date, "%m/%d/%Y"), format = "%m/%d/%Y")