问题描述
我将 db 作为数据库,并将“Cośktoś_był” 作为数据库中的列名。 我尝试过:
temp_df <- db %>%
select('Coś ktoś_był')
但输出:
Error: Can't subset columns that don't exist.
x Column `Cos ktos_byl` doesn't exist.
Run `rlang::last_error()` to see where the error occurred.
我不知道如何更改列名而不更改它。 我无法更改!
解决方法
尝试一下:
library(dplyr)
temp_df <- db %>%
select(matches("[^ -~]"))
或者,在base R
中:
db[,grepl("[^ -~]",names(db))]
这两种方法都会选择名称中包含非ASCII字符的 any 列。如果您需要更具体一些,可以按照以下方式使用:
temp_df <- df %>%
select(matches("^Co[^ -~]"))