简体   繁体   English

在 dplyr group_by 和 count 中找不到对象错误

[英]Object not found error in dplyr group_by and count

I am trying to create a count of as a first step to calculate a percent cover for each category.我正在尝试创建一个计数作为计算每个类别的百分比覆盖率的第一步。 The code below has worked before, but is no longer working.下面的代码以前有效,但不再有效。

I have read other posts on SO and none of them seem to capture the problem I'm experiencing.我已经阅读了关于 SO 的其他帖子,但似乎没有一个能解决我遇到的问题。

Here is a reproducible example of what I'm trying to do:这是我正在尝试做的一个可重现的例子:

 library(dplyr)

cover_data_test<- data.frame( site=c('cram','khq','k50'), 
                     treatment=c('exc','out','exc'), 
                     season=c('fall','spring','fall'),
                     transect=c(1,1,1), 
                     point=c(1,2,3),
                     ground=c('b','l','pb')
                     )
 View(cover_data_test)

  groundcover_test<- cover_data_test%>%
        group_by(season,site,treatment,transect)%>%
        count(ground)

I am still getting this error with the above example:上面的例子我仍然收到这个错误:

"Error in FUN(X[[i]], ...) : object 'b' not found"

Any ideas about what might be going on?关于可能发生什么的任何想法?

The conflicts() function helped me get to the bottom of it! conflicts()函数帮助我找到了它的底部! "count" was listed as a conflict so I edited the code to be r groundcover_test<- cover_data_test %>% group_by(season,site,treatment,transect)%>% dplyr::count(ground) “count”被列为冲突,所以我将代码编辑为r groundcover_test<- cover_data_test %>% group_by(season,site,treatment,transect)%>% dplyr::count(ground)

Adding the double colon operator dplyr:: allowed it to run as expected.添加双冒号运算符dplyr::允许它按预期运行。 Thanks again!再次感谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM