即使使用 DPLYR 包中的 SELECT 存在列,也无法对列进行子集化

Can't subset column even if the column exists using SELECT from DPLYR package

我正在对一个包含 19 列的数据框进行子集化。当我将 CRIMINALCASES 添加到 select() 选项时,它显示错误。

data_1 <- data_kerala%>%
select(CONSTITUENCY, NAME, WINNER, PARTY, GENDER,CRIMINALCASES, AGE, CATEGORY, EDUCATION)

这是错误信息

Error: Can't subset columns that don't exist.
✖ The column `CRIMINALCASES` doesn't exist.
Traceback:

1. data_kerala %>% select(CONSTITUENCY, NAME, WINNER, PARTY, GENDER, 
 .     CRIMINALCASES, AGE, CATEGORY, EDUCATION)
2. withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
3. eval(quote(`_fseq`(`_lhs`)), env, env)
4. eval(quote(`_fseq`(`_lhs`)), env, env)
5. `_fseq`(`_lhs`)
6. freduce(value, `_function_list`)
7. withVisible(function_list[[k]](value))
8. function_list[[k]](value)
9. select(., CONSTITUENCY, NAME, WINNER, PARTY, GENDER, CRIMINALCASES, 
 .     AGE, CATEGORY, EDUCATION)
10. select.data.frame(., CONSTITUENCY, NAME, WINNER, PARTY, GENDER, 
  .     CRIMINALCASES, AGE, CATEGORY, EDUCATION)
11. tidyselect::vars_select(tbl_vars(.data), !!!enquos(...))
12. eval_select_impl(NULL, .vars, expr(c(!!!dots)), include = .include, 
  .     exclude = .exclude, strict = .strict, name_spec = unique_name_spec, 
  .     uniquely_named = TRUE)
13. with_subscript_errors(vars_select_eval(vars, expr, strict, data = x, 
  .     name_spec = name_spec, uniquely_named = uniquely_named, type = type), 
  .     type = type)
14. tryCatch(instrument_base_errors(expr), vctrs_error_subscript = function(cnd) {
  .     cnd$subscript_action <- subscript_action(type)
  .     cnd$subscript_elt <- "column"
  .     cnd_signal(cnd)
  . })
15. tryCatchList(expr, classes, parentenv, handlers)
16. tryCatchOne(expr, names, parentenv, handlers[[1L]])
17. value[[3L]](cond)
18. cnd_signal(cnd)
19. rlang:::signal_abort(x)

不明白为什么说列不存在

这是使用函数 colnames()

的列名

这是 Kaggle 中显示的列名列表

然后尝试在单词之间添加space但没有用

(抱歉,我是 Whosebug 的新手,无法发表评论。)

列名称是否可能实际上是 CRIMINAL CASES(带有 space)或 CRIMINAL\nCASES?

你能试试用反引号 (`) 包裹 CRIMINAL\nCASES 吗?

以下对我来说没有问题:

# creating test tibble
a <- 
  tribble(
  ~"CRIMINAL\nCASES", ~"random",
  "hi", "bye"
)

a %>%
  select(`CRIMINAL\nCASES`)