Minimum reproducible example:
times <- 0:365
df <- data.frame(times)
for (i in 1:5){
for(j in 3:6){
scen_name=paste("Scen",j,i,sep="_")
scen_out <- sample(times)
df <- cbind(df, scen_out)
colnames(df)[length(df)] <- scen_name
}
}
# Get user input for which variable to view / graph
Selection <- "Scen_4_2"
get(paste0('df$',Selection)))
This fails to retrieve the data.
And exists(paste0('df$',Selection)))
returns false - but I can retrieve it perfectly well with df$Scen_4_2
.
Note that I need to reference the variable indirectly because the name is being generated - so checking or directly referencing the variable is irrelevant.