相关疑难解决方法(0)

索引grouped_df对象

尝试grouped_df通过索引选择类对象的列给出"错误:索引超出范围".例如

x <- mtcars %>% group_by(am, gear) %>% summarise_each(funs(sum), disp, hp, drat)
class(x)
#    "grouped_df" "tbl_df"     "tbl"        "data.frame"
# For some reason the first column can be selected...
x[1]
#    Source: local data frame [4 x 1]
#    Groups: am
#    am
#     0
#     0
#     1
#     1    
# ...but any index > 1 fails
x[2] 
#   Error: index out of bounds
# Coercing to data frame does the trick...
as.data.frame(x)[2]
#   gear
#      3
# …
Run Code Online (Sandbox Code Playgroud)

r dplyr

5
推荐指数
1
解决办法
1080
查看次数

标签 统计

dplyr ×1

r ×1