0

An elementary R question. I would like to know if there is any possible way to take the given argument of a function and make it a character string, i.e. use the name of the variable. I am using mtcars dataset and pass mtcars$mpg into my function and like to use the name of the vector in labeling my graph.

If I am passing vectors of a data frame into my function, how do I use the name of the vector as a title in my graph.

eda1 <- function(x){

    par(mfrow = c(1,2), oma = c(0,0,2,0))
    boxplot(x, main = paste("Boxplot", x))
    qqnorm(x)
    qqline(x)
    mtext(text = paste("Test Outliers for", x), outer = TRUE)
    }

I am tyring to figure out what to use in the boxplot and mtext functions where I have x to get "mtcars$mpg" in my function . Suppose I give the command eda1(mtcars$mpg) and obviously the entire vector x is being passed as text.
enter image description here

I tried the quote function as such name <- quote(x) but that just stores "x" in name.

eda1 <- function(x){
    name <- quote(x)
    par(mfrow = c(1,2), oma = c(0,0,2,0))
    boxplot(x, main = paste("Boxplot", name))
    qqnorm(x)
    qqline(x)
    mtext(text = paste("Test Outliers for", name), outer = TRUE)
    }

I would like to store "mtcars$mpg" in the name variable when I give the call eda1(mtcars$mpg).

Thanks

Bhail
  • 385
  • 1
  • 2
  • 18

0 Answers0