小编ale*_*one的帖子

为什么facet_grid工作,但不是facet_wrap?

我想使用faceting,还要控制行数和列数.所以facet_wrap比facet_grid更受欢迎.但是当facet_grid工作时,facet_wrap没有并且给出错误:"至少一个层必须包含用于facetting的所有变量".为什么会这样?我怎样才能在这里使用facet_wrap?

x <- rnorm(8)
y <- x + rnorm(8, sd=0.7)
dd <- data.frame(id=rep(1:4, 2), x=x, y=y)
pp <- ggplot(dd, aes(x, y)) + geom_point()
pp  
pp + facet_grid(. ~ id)  # works
pp + facet_wrap(. ~ id)  # error
Run Code Online (Sandbox Code Playgroud)

r ggplot2

19
推荐指数
1
解决办法
6661
查看次数

在data.table中舍入POSIXct

使用此问题中的相同数据,在data.table v1.9.2中将日期时间舍入到第二个是一个问题.

require(data.table)
options(digits.secs=3)  # usually placed in .Rprofile
DT <- data.table(timestamp=c(as.POSIXct("2013-01-01 17:51:00.707"),
                             as.POSIXct("2013-01-01 17:51:59.996"),
                             as.POSIXct("2013-01-01 17:52:00.059"),
                             as.POSIXct("2013-01-01 17:54:23.901"),
                             as.POSIXct("2013-01-01 17:54:23.914")))
DT
DT[ , round(timestamp)]  # looks good
DT[ , timestamp_rounded := round(timestamp)]  # does not work
DT[ , timestamp_rounded := round(timestamp, units="secs")]  # does not work
DT
#                   timestamp timestamp_rounded
# 1: 2013-01-01 17:51:00.707       1,0,0,24,24
# 2: 2013-01-01 17:51:59.996    51,52,52,54,54
# 3: 2013-01-01 17:52:00.059    17,17,17,17,17
# 4: 2013-01-01 17:54:23.901         1,1,1,1,1
# 5: 2013-01-01 17:54:23.914         0,0,0,0,0
Run Code Online (Sandbox Code Playgroud)

我找到了一个解决方案lubridate …

r posixct data.table

2
推荐指数
1
解决办法
596
查看次数

标签 统计

r ×2

data.table ×1

ggplot2 ×1

posixct ×1