R 求加权中值
我有以下数据集:R 求加权中值,r,aggregate,weighted-average,R,Aggregate,Weighted Average,我有以下数据集: df <- data.frame( C = c(1,2,3,1,2,3,1,2,3,1), weight = c(1,1.5,2,2,1.5,1,2,1,1.5,2.5), time = c(15,20,30,45,60,15,20,30,45,60) ) dfgithub上的bigvis包中有一个加权中值函数 library(devtools) install_github("bigvis") aggregate不适用于需要多个向量输入的函
df <- data.frame(
C = c(1,2,3,1,2,3,1,2,3,1),
weight = c(1,1.5,2,2,1.5,1,2,1,1.5,2.5),
time = c(15,20,30,45,60,15,20,30,45,60)
)
dfgithub上的bigvis
包中有一个加权中值函数
library(devtools)
install_github("bigvis")
aggregate
不适用于需要多个向量输入的函数。改用plyr
中的ddply
library(plyr)
ddply(df, .(C), summarise, wm = weighted.median(time, weight))
尝试安装bigvis时,我遇到以下错误:函数中出现错误(type,msg,asError=TRUE):无法解析主机:github.com;主人不found@user2568648你在公司网络上吗?如果是这样,最可能的解释是网络管理员阻止了对github的访问。尝试在浏览器中访问该站点。
library(plyr)
ddply(df, .(C), summarise, wm = weighted.median(time, weight))