Edit: a near-duplicate
How to reference column names that start with a number, in data.table
The post above regards data.table
. The problem is similar but technically package-dependent, but the solution is the same.
Start of original post
I'm unable to figure out how to filter the following column with dplyr::filter
set.seed(1)
library(dplyr)
df <- as.data.frame(matrix(sample(c(TRUE, FALSE), 10, replace=TRUE), ncol=1)) %>%
setNames(c(paste0("1", letters[1])))
# 1a
# 1 TRUE
# 2 TRUE
# 3 FALSE
# 4 FALSE
# 5 TRUE
# 6 FALSE
# 7 FALSE
# 8 FALSE
# 9 FALSE
# 10 TRUE
df[df$"1a"==TRUE,]
# [1] TRUE TRUE TRUE TRUE
df %>% dplyr::filter("1a"==TRUE)
# [1] 1a
# <0 rows> (or 0-length row.names)