[R] Convert a character string to variable names
Erin Hodgess
er|nm@hodge@@ @end|ng |rom gm@||@com
Mon Feb 7 23:55:13 CET 2022
Hello!
I have a character string that is a vector of variable names. I would like
to use those names to access the variables and create a matrix.
I tried the following:
> .x
[1] "mtcars$disp" "mtcars$hp" "mtcars$cyl"
> .y <- NULL
> for(i in 1:3) {
+ .y[i] <- c(as.name(.x[[i]]))
+ }
> .y
[[1]]
`mtcars$disp`
[[2]]
`mtcars$hp`
[[3]]
`mtcars$cyl`
But I am having trouble converting the variables in .y into a matrix.
I tried all kinds of stuff with bquote, deparse, do.call, but no good.
I have a feeling that it's something simple, and I'm just not seeing it.
Thanks,
Erin
Erin Hodgess, PhD
mailto: erinm.hodgess using gmail.com
[[alternative HTML version deleted]]
More information about the R-help
mailing list