作者celestialgod (攸蓝)
看板R_Language
标题Re: [问题] iris不同品种所占比例的圆饼图
时间Wed Jun 17 13:26:48 2015
推文很难读懂,我最後还是回文好了
这里提供三个方法
## tapply + with
X = with(iris, tapply(Sepal.Length, Species, sum))
y = X / sum(X)
## plyr
library(plyr)
X = ddply(iris, .(Species), summarise, tsl = sum(Sepal.Length))
y = X$tsl / sum(X$tsl)
## dplyr
library(dplyr)
X = summarise(group_by(iris, Species), tsl = sum(Sepal.Length))
y = X$tsl / sum(X$tsl)
※ 引述《yeuan (心要够坚定)》之铭言:
: [问题类型]:
: 分类後计算比例绘制圆饼图
: [软体熟悉度]:
: 新手(没写过程式,R 是我的第一次)
: [问题叙述]:
: 想计算iris三种品种的Sepal.Length各占多少比例 并制作圆饼图
: 因为知道的指令有限 一时想不出更好的 只有土法炼钢的作法
: 想请教有没有更简洁的写法
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.205.27.107
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1434518811.A.9F1.html
1F:推 yeuan: 谢谢版主提供许多不同的作法 06/18 09:26