【发布时间】:2013-04-11 00:13:31
【问题描述】:
我正在尝试按年份对旧金山的所有日期房屋进行分组。我正在使用以下代码
geo_big$month <- as.Date(paste0(strftime(geo_big$date, format = "%Y-%m"), "-01"))
geo_big$date_r <- cut(geo_big$month, breaks = as.Date(c("2003-04-01", "2004-01-01", "2005-01-01", "2006-01-01", "2007-01-01", "2008-11-01")), include.lowest = TRUE, labels = as.Date(c("2003-01 - 2004-12", "2004-01 - 2004-12", "2005-01 - 2005-12", "2006-01 - 2006-12", "2007-01 - 2007-12", "2008-01 - 2008-11")))
并收到此消息:
Error in charToDate(x) :
character string is not in a standard unambiguous format
有人知道怎么回事吗?
【问题讨论】:
-
geo_big$date存储为什么格式? -
as.Date(strptime(geo_big$date, "%Y-%m-%d"))
-
看起来可疑的一个方面是“标签”参数。应该是字符向量而不是日期。看起来有问题的另一个方面(在查看
help(cut.Date)之后)是中断参数。使用一系列 Date 值进行测试对我来说会返回一个错误。