R 分组依据不进行汇总

R 分组依据不进行汇总,r,dplyr,R,Dplyr,我在dplyr图书馆工作很辛苦。我一直在尝试实现一段相对简单的代码,但出于某种原因,当我按一个变量分组并尝试求和以得到该变量的总数时,我只得到NA值。这是我的档案: 这是代码: library (dplyr) #we set the working directory setwd("~/asado/R/emp") ##we list the files list.files() ##we load the csv files emp1 <- read.csv("AI_EMP_CT_A.c

我在dplyr图书馆工作很辛苦。我一直在尝试实现一段相对简单的代码,但出于某种原因,当我按一个变量分组并尝试求和以得到该变量的总数时,我只得到NA值。这是我的档案:

这是代码:

library (dplyr)
#we set the working directory
setwd("~/asado/R/emp")
##we list the files
list.files()
##we load the csv files
emp1 <- read.csv("AI_EMP_CT_A.csv", sep=',')
##emp1 contains employment information for US counties with naics classification
##empva is another part of the same dataset
empva <- read.csv("AI_EMP_CT_VA_A.csv", sep=',')
##we merge our files, they have the same dimentions so rbind works
emp <- data.frame(rbind(emp1, empva))
##we create a variable to summarize our data
##and make sure is stored as character
emp$naics <- as.character(substring(emp$Mnemonic,3,6))

##we try to summarize by the variable naics, summing for Dec.2013
useemp<- emp%.% group_by(naics) %.%
  summarize(total=sum(Dec.2013, na.rm=T))
##the resulting dataframe shows NA
head(useemp)
库(dplyr)
#我们设置了工作目录
setwd(“~/asado/R/emp”)
##我们列出这些文件
list.files()
##我们加载csv文件

emp1这对我很有用,但是读取empva文件很复杂,因为最后一列, 2013年12月填写了
且未与其分离。您确定它被读取为数字吗

useemp <- emp %>% group_by(naics) %>%
      summarize(total=sum(Dec.2013, na.rm=T))
    head(useemp)

    Source: local data frame [6 x 2]

      naics     total
    1  2111 132.04674
    2  2121  24.84666
    3  2122  23.90470
    4  2123  17.57697
    5  2131  77.20557
    6  2211 119.30697
useemp%分组依据(naics)%>%
汇总(总计=总计(2013年12月,不适用rm=T))
负责人(使用环境管理计划)
来源:本地数据帧[6 x 2]
naics总数
1  2111 132.04674
2  2121  24.84666
3  2122  23.90470
4  2123  17.57697
5  2131  77.20557
6  2211 119.30697

他们询问的是dplyr,而不是plyr。Joran,我使用dplyr的原因是,plyr将花费永远的时间。我上传的文件只是原始文件的一个样本,包含一百万个观察值和变量。是的,2013年12月是数字文件,我认为问题在于使用%.%而不是%>%。谢谢。这是
na.rm
而不是
rm.na
。我没有测试你的数据,但尝试了两件事:将
dplyr
更新到最新版本(其中%>%替换了%.%,尽管我仍然可以使用),并使用
dplyr::summary(total=sum(2013年12月,na.rm=t))
确保你与
plyr
没有冲突。这会改变什么吗?