【发布时间】:2017-02-07 00:30:48
【问题描述】:
我试图根据this SO post 返回每个组的平均值,但在这种情况下,解决方案似乎不起作用。有人可以解释为什么我仍然得到一个全局平均值吗?
tmp = tempfile(fileext = ".xlsx")
download.file(url = "https://www.bls.gov/emp/ind-occ-matrix/occupation.xlsx", destfile = tmp, mode="wb")
library(readxl)
csv <- read_excel(tmp,sheet=8)
########################################################
colnames(csv)<-c("title","code","Occupation Type","Employment2014","Employment2024" ,"EmploymentChange2014-24.Num","EmploymentChange2014-24.Percent","Percent self employed2014","Job openings due to growth and replacements2014-24","Median annual wage2015","Typical education needed for entry","Work experience in a related occupation","Typical on-the-job training needed")
csv<-csv[csv[,3]=="Line item",]
csv$"Median annual wage2015"<-as.numeric(csv$"Median annual wage2015")
library(dplyr)
csv%>%group_by(csv$"Typical education needed for entry")%>%summarise(n=n(),mean=mean(csv$"Median annual wage2015",na.rm=T))
【问题讨论】: