2014-05-15 2 views
0

예는 Phil Spectre의 환상적인 "David Manipulation with R"의 예제이지만 오류가 발생합니다.R에서 테이블에 쓸 때 날짜 클래스로 변환하는 중 오류가 발생했습니다.

#write a gzipped csv file created from a data frame 

gfile = gzfile("mydata.gz") 
write.table("mydata, sep = ",", file = gfile") 

#Goal is to test a conversion from char to Date objects with function textConnection() 
sample = textConnection("2002-2-29 1 0 
         2002-4-29 1 5 
         2004-10-4 2 0") 

read.table(sample, colClasses = c("Date", NA, NA)) 

Error in charToDate(x) : 
    character string is not in a standard unambiguous format 

#next mydata = scan(unz("data.zip", "mydata.txt")) 
+0

이입니다. 그런 식으로 이런 경우에 좋은 'NA'를 얻었고 그 이유를 조사하는 것이 더 쉽습니다. – Roland

+1

Btw., 왜 누군가 David를 조작하고 싶습니까? 그는 정말 좋은 사람이야. – Roland

답변

2

2 월 29 일 2002 년에 존재하지 않았다 : 난 항상 문자로 날짜에 읽고이어서`format` 문자열을 사용하여`Date`s로 변환하는 이유

as.Date("2002-02-28") 
#[1] "2002-02-28" 
as.Date("2002-02-29") 
#Error in charToDate(x) : 
# character string is not in a standard unambiguous format 
as.Date("2004-02-29") 
#[1] "2004-02-29" 
관련 문제