string - Convert Variables to characters in R -
i want take names of variables in a
, results in b
a <- list(eurusd,usdjpy,cadjpy) b <- c("eurusd", "usdjpy", "cadjpy")
how can instead of writing manually?
first, r evaluates lazily, when assigned list variable a
expression list(eurusd, usdjpy, cadjpy)
got evaluated. unless 3 objects named , have same names, not possible names.
what try parse output of ls()
: 6 character caps names in namespace.
example:
eurusd <- runif(10) usdjpy <- runif(10) cadjpy <- runif(10) blablabla <- 'unused variable' currency_pairs <- ls(pattern='^[a-z]{6}$') print(currency_pairs) [1] "cadjpy" "eurusd" "usdjpy"
Comments
Post a Comment