I want to select the column named "b" in a tibble
. "b" is the value of a variable called col_name
.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
col_name <- "b" # the column to select
df <- tibble(a = c(1,2,3), b = c(2,4,6))
df$b
#> [1] 2 4 6
# But I want to use a variable to dynamically select the column
df$col_name
#> Warning: Unknown or uninitialised column: `col_name`.
#> NULL
Created on 2020-10-12 by the reprex package (v0.3.0)