Reputation: 1906
I want to re-arrange the columns of a df using dplyr::select
programatically
A non R user is going to execute the code and this person will provide two inputs as follows:
report.month <- "Jul"
report.year <- 2017
Only the month will change, all other names in the df will be the same
df1 <- data.frame(
country = "AU",
Jul_2017 = 500,
Customer = "some guy")
country Customer Jul_2017
AU some guy 500
reporting.month.name <- as.symbol(paste(report.month, report.year, sep = "_"))
df1 %>% select(country, Customer, reporting.month.name)
Error: `reporting.month.name` must resolve to integer column positions, not a symbol
Any advice/help is very much appreciated
Upvotes: 0
Views: 5342
Reputation: 4224
Remove the as.symbol() from your code, like this:
reporting.month.name <- paste(report.month, report.year, sep = "_")
df1 %>% select(country, Customer, reporting.month.name)
Output:
country Customer Jul_2017
1 AU some guy 500
Upvotes: 1