Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R语言中,写入表时转换为日期类时出错_R_Read.table_Write.table - Fatal编程技术网

在R语言中,写入表时转换为日期类时出错

在R语言中,写入表时转换为日期类时出错,r,read.table,write.table,R,Read.table,Write.table,例子来自菲尔·斯佩克特(Phil Specter)写的一本非常精彩的书《用R操纵大卫》(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 t

例子来自菲尔·斯佩克特(Phil Specter)写的一本非常精彩的书《用R操纵大卫》(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"))

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"

这就是为什么我总是以字符形式读入日期,然后使用
格式
字符串转换为
日期
s。这样我就可以得到一些关于这些案例的好的
NA
s,并且更容易调查为什么会发生这些事情。顺便说一句,为什么有人想要操纵大卫?他真是个好人。