ruben.lfdz
ruben.lfdz

Reputation: 143

In R how can I filter a column which name is a number

this is my code

centros <- eventos %>%
filter(type_id==1 & 2:1 & Name == 'jack')

data sample

type_id      Name         2
1           jack          1
2           Mary          NA
4           Peter         1

Thanks in advance

Upvotes: 2

Views: 38

Answers (1)

akrun
akrun

Reputation: 887223

We can use backquotes

library(dplyr)
centros <- eventos %>%
               filter(type_id==1, `2` == 1,  Name == 'jack')

centros
#  type_id Name 2
#1       1 jack 1

data

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))

Upvotes: 2

Related Questions