访问';家长';在dplyr中使用group_by后的data.frame
我想比较一个变量的标准偏差和一个因子分组后变量的标准偏差 这是总体sd() 但是,一旦我使用了group_by,我就无法访问它访问';家长';在dplyr中使用group_by后的data.frame,r,dplyr,R,Dplyr,我想比较一个变量的标准偏差和一个因子分组后变量的标准偏差 这是总体sd() 但是,一旦我使用了group_by,我就无法访问它 iris %.% group_by(Species) %.% summarise( Species.SD = sd(Sepal.Length), Overall.SD = sd(iris$Sepal.Length), Species.SD < Overall.SD ) iris%。% 按(物种)划分的组别% 总结( 种SD=S
iris %.%
group_by(Species) %.%
summarise(
Species.SD = sd(Sepal.Length),
Overall.SD = sd(iris$Sepal.Length),
Species.SD < Overall.SD
)
iris%。%
按(物种)划分的组别%
总结(
种SD=SD(萼片长度),
整体SD=SD(虹膜$萼片长度),
Species.SD
有没有办法让dplyr回顾整个数据集?在使用
mutate
对数据进行分组之前,我会计算overall.SD
,以便其他数据保持原样
iris %>%
mutate(Overall.SD = sd(Sepal.Length)) %>% # you can use mutate instead of summarise here
group_by(Species) %>%
summarise(Species.SD = sd(Sepal.Length),
Overall.SD = Overall.SD[1], # You could also remove this line if you just want the comparison and don't need to display the actual Overall.SD
Species.SD < Overall.SD)
iris%>%
mutate(total.SD=SD(Sepal.Length))%>%#您可以使用mutate而不是在这里总结
组别(种类)%>%
总结(种类SD=SD(萼片长度),
Overall.SD=Overall.SD[1],#如果只需要比较,而不需要显示实际的Overall.SD,也可以删除此行
物种SD<总体SD)
这是一个很好的方法。我没有想到用Overall.SD[1]
来处理第一个案例,并以这种方式分配它。非常感谢。
iris %>%
mutate(Overall.SD = sd(Sepal.Length)) %>% # you can use mutate instead of summarise here
group_by(Species) %>%
summarise(Species.SD = sd(Sepal.Length),
Overall.SD = Overall.SD[1], # You could also remove this line if you just want the comparison and don't need to display the actual Overall.SD
Species.SD < Overall.SD)