简体   繁体   English

R dplyr 过滤列名中的空格/特殊字符

[英]R dplyr filter space/special characters in column names

require(dplyr)
sampleDF <- data.frame("Column A" = c(1,2,3))
sampleDF %>%
  dplyr::filter(
    `Column A` > 2
  )

How should I fix the codes above so it works?我应该如何修复上面的代码以使其正常工作? I don't want to change the name.我不想改名字。

dplyr is probably not the problem, because in general only dots and underscores are allowed in variable names, but no spaces. dplyr 可能不是问题,因为通常变量名称中只允许使用点和下划线,但不允许使用空格。 If you would like to include a quoted name under all circumstances, maybe:如果您想在所有情况下都包含带引号的名称,也许:

require(dplyr)
require(rlang)
sampleDF <- data.frame("Column A" = c(1,2,3))
sampleDF %>%
  dplyr::filter(
    eval_tidy(quo("Column A")) > 2 # OR: eval(quote("Column A")) > 2
  )

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

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