Re: [問題] iris不同品種所占比例的圓餅圖

作者: celestialgod (天)   2015-06-17 13:26:48
推文很難讀懂,我最後還是回文好了
這裡提供三個方法
## 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各占多少比例 並製作圓餅圖
: 因為知道的指令有限 一時想不出更好的 只有土法煉鋼的作法
: 想請教有沒有更簡潔的寫法
作者: yeuan (心要夠堅定)   2015-06-18 09:26:00
謝謝版主提供許多不同的作法

Links booklink

Contact Us: admin [ a t ] ucptt.com