R: how to build a mathematical expression from a symbol object?

In R, I want to create a graph with an x-axis label expression(varname), where varnameis the symbol object. For instance:

varname <- "beta[1]"
hist(rnorm(20),xlab=expression(varname))

But it gives me a schedule with xlab="varname", and not xlab=expression(beta[1]). How to convince to expression()evaluate a variable?

+3
source share
1 answer

You can do

hist(rnorm(20),xlab=parse(text=varname))
+10
source

Source: https://habr.com/ru/post/1749335/


All Articles