在 R 中,如何过滤名称为数字的列
In R how can I filter a column which name is a number
这是我的代码
centros <- eventos %>%
filter(type_id==1 & 2:1 & Name == 'jack')
数据样本
type_id Name 2
1 jack 1
2 Mary NA
4 Peter 1
提前致谢
我们可以使用backquotes
library(dplyr)
centros <- eventos %>%
filter(type_id==1, `2` == 1, Name == 'jack')
centros
# type_id Name 2
#1 1 jack 1
数据
eventos <- structure(list(type_id = c(1L, 2L, 4L), Name = c("jack", "Mary",
"Peter"), `2` = c(1L, NA, 1L)), class = "data.frame", row.names = c(NA,
-3L))
这是我的代码
centros <- eventos %>%
filter(type_id==1 & 2:1 & Name == 'jack')
数据样本
type_id Name 2
1 jack 1
2 Mary NA
4 Peter 1
提前致谢
我们可以使用backquotes
library(dplyr)
centros <- eventos %>%
filter(type_id==1, `2` == 1, Name == 'jack')
centros
# type_id Name 2
#1 1 jack 1
数据
eventos <- structure(list(type_id = c(1L, 2L, 4L), Name = c("jack", "Mary",
"Peter"), `2` = c(1L, NA, 1L)), class = "data.frame", row.names = c(NA,
-3L))