As we know, it is each to subset a column by a $ sign and the name of a column.
df <- data.frame(matrix(rnorm(12),4,3))
df$X1
what if I want to subset a column with a variable?
a="X1"
df$a
As we know, it is each to subset a column by a $ sign and the name of a column.
df <- data.frame(matrix(rnorm(12),4,3))
df$X1
what if I want to subset a column with a variable?
a="X1"
df$a
You can have the same output with this format:
> df$X1
[1] 0.1591573 1.3328099 -0.2382000 -0.7364309
> df[,a]
[1] 0.1591573 1.3328099 -0.2382000 -0.7364309