Calling variable in matrix with another variable, R

It looks like you’re talking about a data frame, not a matrix. You can use names(Fires) to get a vector of column names, and use that to go from your variables to a column reference:

X <- 1
Y <- 1
column.name <- paste0( X, Y )
Fires[ , column.name ]

EDIT: in fact, you can even skip the match step.

Leave a Comment