【发布时间】:2017-11-15 15:01:30
【问题描述】:
有人可以解释为什么table()在 dplyr-magrittr 管道操作链中不起作用吗?这是一个简单的表示:
tibble(
type = c("Fast", "Slow", "Fast", "Fast", "Slow"),
colour = c("Blue", "Blue", "Red", "Red", "Red")
) %>% table(.$type, .$colour)
sort.list(y) 中的错误:对于“sort.list”,“x”必须是原子的 您是否在列表中调用了“排序”?
但这当然有效:
df <- tibble(
type = c("Fast", "Slow", "Fast", "Fast", "Slow"),
colour = c("Blue", "Blue", "Red", "Red", "Red")
)
table(df$type, df$colour)
Blue Red
Fast 1 2
Slow 1 1
【问题讨论】:
-
你也可以使用
df %>% group_by(type, colour) %>% tally() -
您也可以使用
df %>% select(type,colour) %>% table(select以防万一您有其他列)。