How to List Variables in R?

Spread the love

Problem –

You want to know what variables and functions are defined in your workspace.

Solution –

To list all variables and functions in your workspace, we use the ls() function.

Let’s define some variables and function to illustrate it.

a <- 5
b <- 10
c <- a + b
f <- function(n, p) sqrt(p * (1-p) / n)

Now let;s use the ls() function.

> ls()
[1] "a" "b" "c" "f"

You can also see your variables and functions in the environment pane in RStudio.

If you want more than just a list of names, try the ls.str(). This will also tell you something about each variables.

> ls.str()
a :  num 5
b :  num 10
c :  num 15
f : function (n, p) 

Rating: 1 out of 5.

Posted in RTagged

Leave a Reply