Given a table of the form:
a b c
X1 0 1 0
X2 1 0 0
X3 1 0 0
In order to pull a column from the table:
col.1 <- table$a
Assume you have a variable:
col.name <- 'a'
col.1 <- table$col.name
Why doesn’t this work? Is there a way to make this work?
It doesn’t work because the “$” operator does not evaluate its argument. What you need is to use “[” or “[[“. (It’s not a good idea to call your table. “table”. It confuses users who use the
tablefunction.)