全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
11421 2
2016-03-30
想做一个年-月的时间直方统计如下:
> test<-as.Date("2008-12-19")
> test
[1] "2008-12-19"
> str(test)
Date[1:1], format: "2008-12-19"
> test1<-strftime(test,format = "%Y-%m")
> test1
[1] "2008-12"
> str(test1)
chr "2008-12"
> test2<-as.Date(test1)
Error in charToDate(x) : 字符串的格式不够标准明确
> test3<-strftime(test,format="%Y")
> test3
[1] "2008"
> str(test3)
chr "2008"

年-月-日转换成年-月或年后格式就不是Date型而是变成了chr型,原来年-月-日Date型时可以用geom_histogram直接对时间做直方统计,转换成后年-月或年chr型后就不行了,报错如下:
Error: StatBin requires a continuous x variable the x variable is discrete. Perhaps you want stat="count"?
该如何解决?

另外我用年-月-日做直方统计时提示信息如下:
stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
这个binwidth是指的30日吗?
谢谢大家
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-3-30 20:11:06
可以用zoo包里的as.yearmon
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-3-31 21:43:23
qoiqpwqr 发表于 2016-3-30 20:11
可以用zoo包里的as.yearmon
好的谢谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群