Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 求加权中值_R_Aggregate_Weighted Average - Fatal编程技术网

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))