使用 count() 时出现 dplyr 错误

问题描述 投票:0回答:2

当我执行以下代码时:

merged <- interrogations %>% 
             filter(person=='accused') %>% 
             count(caseId)

我收到错误:

#Error in count(., caseId) : object 'caseId' not found

但是,当我用

interrogations$caseId
查找时,变量
interrogations$caseId
确实存在。我做错了什么?

变量名称是德语,但我希望这无论如何都有帮助(interrogations=einvernahmen):

structure(list(id = 1:6, person = c("Beschuldigter", "Auskunftsperson", 
"Beschuldigter", "Auskunftsperson", "Beschuldigter", "Beschuldigter"
), behoerde = c("Pol", "Pol", "Pol", "Pol", "Pol", "Pol"), datum = c("10.05.2013", 
"29.04.2013", "10.05.2013", "06.04.2013", "15.05.2013", "10.05.2013"
), anwBesch = c("ja", "nein", "ja", "nein", "ja", "ja"), anwVert =  c("ja", 
"nein", "ja", "nein", "ja", "ja"), verhalten = structure(c(2L, 
NA, 5L, 1L, 4L, 5L), .Label = c("", "Bestreiten", "Geständnis", 
"Schweigen", "Teilgeständnis"), class = "factor"), caseId = c(7L, 
7L, 7L, 7L, 7L, 7L), user = c(14L, 14L, 14L, 14L, 14L, 14L), 
dokuAussage = c("2", "", "2", "1", "2", "2"), dokuAussageAnd = c("", 
"", "", "", "", ""), uebersetzer = c("", "", "", "", "", 
""), offenEinv = c("", "", "", "", "", "")), .Names = c("id", 
"person", "behoerde", "datum", "anwBesch", "anwVert", "verhalten", 
"caseId", "user", "dokuAussage", "dokuAussageAnd", "uebersetzer", 
"offenEinv"), row.names = c(NA, -6L), class = c("tbl_df", "tbl", 
"data.frame"))
r count dplyr plyr tidyverse
2个回答
0
投票
interrogations %>% 
   filter(person == 'Auskunftsperson') %>% 
   count(caseId)

# A tibble: 1 x 2
  caseId     n
   <int> <int>
1      7     2


interrogations %>% 
   group_by(person) %>% 
   summarise(freq = n())

# A tibble: 2 x 2
  person           freq
  <chr>           <int>
1 Auskunftsperson     2
2 Beschuldigter       4

0
投票

我也刚刚遇到了这个错误,幸运的是我能够追溯到加载 Rmisc 包。对于将来遇到此问题的人,请尝试重新启动 R 会话,重新加载除 Rmisc 之外的所有包并再次运行它。

© www.soinside.com 2019 - 2024. All rights reserved.