看板 R_Language 關於我們 聯絡資訊
推文很難讀懂,我最後還是回文好了 這裡提供三個方法 ## 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://www.ptt.cc/bbs/R_Language/M.1434518811.A.9F1.html
yeuan: 謝謝版主提供許多不同的作法 06/18 09:26