【发布时间】:2018-05-28 14:00:17
【问题描述】:
考虑以下玩具数据和计算:
library(dplyr)
df <- tibble(x = 1)
stats::sd(df$x)
dplyr::summarise(df, sd_x = sd(x))
第一个计算结果为NA,而第二个计算结果包含在 dplyr 函数summarise 中时产生NaN。我希望这两种计算都会产生相同的结果,但我想知道它们为什么不同?
【问题讨论】:
-
我可以复制。 dplyr 版本 0.7.4 - CRAN 的最新版本。
-
这里也一样。但是,您需要它做什么?如果您询问
is.na(),两者都返回TRUE。 -
有趣。对我来说,结果都是 NA:
> stats::sd(df$x) [1] NA和> dplyr::summarise(df, sd_x = sd(x)) # A tibble: 1 x 1 sd_x <dbl> 1 NA -
@storaged 你使用的是什么版本的
dplyr?