我有以下数据框架
> S
Source: local data frame [1,991 x 3]
Groups: exp
exp year commval
1 alb 1995 186
2 alb 1997 232
3 alb 1998 244
4 alb 2000 251
5 alb 1996 275
6 alb 1999 290
7 alb 2001 313
8 alb 2002 358
9 alb 2003 471
10 alb 2004 608
.. ... ... ...
Run Code Online (Sandbox Code Playgroud)
我想过滤年份== 1995而不是重新订购:
> S %>% filter(year == 1995) %>% arrange(commval)
Source: local data frame [130 x 3]
Groups: exp
exp year commval
1 alb 1995 186
2 are 1995 20266
3 arg 1995 21178
4 arm 1995 60
5 aus 1995 49855
6 aut 1995 50115
7 aze 1995 102
8 bel 1995 150850
9 ben 1995 182
10 bfa 1995 231
.. ... ... ...
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,结果不是在commval上排序,而是在exp上排序.我在这做错了什么?
有关conflict()和sessionInfo()的更多信息:
> conflicts()
[1] "filter" "body<-" "intersect" "kronecker" "setdiff" "setequal" "union"
> sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.3.0.2 igraph_0.7.1 reshape2_1.4.1
loaded via a namespace (and not attached):
[1] assertthat_0.1 DBI_0.3.1 lazyeval_0.1.10 magrittr_1.5 parallel_3.1.2 plyr_1.8.1
[7] Rcpp_0.11.3 stringr_0.6.2 tools_3.1.2
Run Code Online (Sandbox Code Playgroud)
从输出
Source: local data frame [1,991 x 3]
Groups: exp
Run Code Online (Sandbox Code Playgroud)
我们可以看到您的数据按分组exp.这意味着当您安排时,您将安排这些小组.如果这不是你想要的,那就去做吧
S %>% filter(year == 1995) %>% ungroup() %>% arrange(commval)
Run Code Online (Sandbox Code Playgroud)
在安排之前取消组合数据
| 归档时间: |
|
| 查看次数: |
397 次 |
| 最近记录: |