我正在查看dplyr包中的“window-function”vignette,您可以使用以下命令打开它:
vignette("window-functions", package="dplyr")第一个示例似乎没有产生正确的结果。
我键入以下内容:
library(dplyr)
library(Lahman)
batting <- select(tbl_df(Batting), playerID, yearID, teamID, G, AB:H)
batting <- arrange(batting, playerID, yearID, teamID)
players <- group_by(batting, playerID)
filter(players, min_rank(desc(H)) <= 2 & H > 0)并获取:
Source: local data frame [32,724 x 7]
Groups: playerID
playerID yearID teamID G AB R H
1 aaronha01 1966 ATL 158 603 117 168
2 aaronha01 1970 ATL 150 516 103 154
3 aaronto01 1962 ML1 141 334 54 77
4 aaronto01 1963 ML1 72 135 6 27
5 aaronto01 1965 ML1 8 16 1 3
6 aaronto01 1968 ATL 98 283 21 69
7 aaronto01 1969 ATL 49 60 13 15
8 aaronto01 1970 ATL 44 63 3 13
9 abadan01 2003 BOS 9 17 1 2
10 abadfe01 2012 HOU 37 7 0 1
.. ... ... ... ... ... ... ...例如,这是aaronto01的错误输出。它应该是:
subset(players, playerID == "aaronto01") %.% filter(min_rank(desc(H)) <= 2 & H > 0)
Source: local data frame [2 x 7]
playerID yearID teamID G AB R H
1 aaronto01 1962 ML1 141 334 54 77
2 aaronto01 1968 ATL 98 283 21 69dplyr有问题吗?或者有人能找出我做错了什么?
发布于 2014-05-06 01:27:38
供参考:
此错误已在dplyr 0.1.3中记录,并已在Github上的开发版本中修复。
https://github.com/hadley/dplyr/issues/313
同时,使用devtools直接从repo安装0.2.0。
library(devtools)
devtools::install_github("hadley/dplyr")https://stackoverflow.com/questions/23474962
复制相似问题