我基本上是在寻找与R中的以下python代码相当的代码:
df.groupby('Categorical')['Count'].count()[0] 以下是我在R中所做的工作:
by(df$count,df$Categorical,sum) 这完成了与第一段代码相同的任务,但我想知道如何将索引值存储到R中的变量(新到R)中。
发布于 2019-05-01 02:09:26
基于by代码,我们似乎可以使用(假设'count‘是1s列)
library(dplyr)
out <- df %>%
group_by(Categorical) %>%
summarise(Sum = sum(count))如果列' count‘也有其他值,则python函数将接受’分类‘列的频率计数。所以,一个类似的选择是
out <- df %>%
count(Categorical) %>%
slice(1) %>%
pull(n)https://stackoverflow.com/questions/55930827
复制相似问题