R之ddlpy函数学习[转载]
生活随笔
收集整理的這篇文章主要介紹了
R之ddlpy函数学习[转载]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自:https://www.cnblogs.com/aloiswei/p/6032513.html
1.函數
ddply(.data, .variables, .fun = NULL, ..., .progress = "none",.inform = FALSE, .drop = TRUE, .parallel = FALSE, .paropts = NULL)?
2.例子
# Summarize a dataset by two variables dfx <- data.frame(group = c(rep('A', 8), rep('B', 15), rep('C', 6)),sex = sample(c("M", "F"), size = 29, replace = TRUE),age = runif(n = 29, min = 18, max = 54) ) head(dfx)group sex age 1 A M 22.44750 2 A M 52.92616 3 A F 30.00443 4 A M 39.56907 5 A M 18.89180 6 A F 50.81139 #Note the use of the '.' function to allow # group and sex to be used without quoting ddply(dfx, .(group, sex), summarize,mean = round(mean(age), 2),sd = round(sd(age), 2))group sex mean sd#運行結果 1 A F 40.41 14.71 2 A M 30.35 13.17 3 B F 34.81 12.76 4 B M 34.04 13.36 5 C F 35.09 13.39 6 C M 28.53 4.57?
需要加載包
library(plyr)?
釋義:也就是按照第二個參數進行分類應用第三個參數(函數處理),對group和sex均相同的分為一類,進行應用第三個參數funtion處理!。
轉載于:https://www.cnblogs.com/BlueBlueSea/p/10104924.html
總結
以上是生活随笔為你收集整理的R之ddlpy函数学习[转载]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于xmpp openfire smac
- 下一篇: Request参数值自动去空格