使用 R 查找每个独特动物品种的平均值和标准差
只是快速刷新一下。我这里有一个数据集,我需要找到独特品种的平均值、标准差等。我知道我以前做过类似的事情,但就是无法将脚本组合在一起。
我的数据集:
aid <- c(1,2,3,4,5,6)
breed <- c("hol","hol","bra","bra","ang","ang")
weight <- c(400,250,450,500,445,345)
data <-data.frame(aid,breed,weight)
我想找到不同品种(荷斯坦、婆罗门和安格斯)的平均值,标准差,
我将感谢您的帮助。
波阿萨
Just a quick refresh. I have a data set here which I need to find the mean, sd, etc of unique breeds. I knew that I have done something like this before but just could not get the script together.
My data set:
aid <- c(1,2,3,4,5,6)
breed <- c("hol","hol","bra","bra","ang","ang")
weight <- c(400,250,450,500,445,345)
data <-data.frame(aid,breed,weight)
I would like to find the mean, sd for the different breeds (holstein, brahman and angus)
I would appreciate your help.
Poasa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用聚合方法找到不同品种的平均体重:
mean_weight <-aggregate(data$weight, by = list(data$breed),mean)
You could find the mean weight for the different breeds with the aggregate method:
mean_weight <-aggregate(data$weight, by = list(data$breed), mean)