0

示例来自 Phil Specter 的非常棒的书“David Manipulation with 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"))
4

1 回答 1

2

2002 年不存在 2 月 29 日:

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"
于 2014-05-15T12:00:17.067 回答