We can use RStudio help:
We can also use R help system:
or alternatively:
or alternatively:
We can also search for operators, for instance:
Most pages will have an example section. We can run all the examples from a given function using:
rnorm> require(graphics)
rnorm> dnorm(0) == 1/sqrt(2*pi)
[1] TRUE
rnorm> dnorm(1) == exp(-1/2)/sqrt(2*pi)
[1] TRUE
rnorm> dnorm(1) == 1/sqrt(2*pi*exp(1))
[1] TRUE
rnorm> ## Using "log = TRUE" for an extended range :
rnorm> par(mfrow = c(2,1))
rnorm> plot(function(x) dnorm(x, log = TRUE), -60, 50,
rnorm+ main = "log { Normal density }")
rnorm> curve(log(dnorm(x)), add = TRUE, col = "red", lwd = 2)
rnorm> mtext("dnorm(x, log=TRUE)", adj = 0)
rnorm> mtext("log(dnorm(x))", col = "red", adj = 1)
rnorm> plot(function(x) pnorm(x, log.p = TRUE), -50, 10,
rnorm+ main = "log { Normal Cumulative }")
rnorm> curve(log(pnorm(x)), add = TRUE, col = "red", lwd = 2)
rnorm> mtext("pnorm(x, log=TRUE)", adj = 0)
rnorm> mtext("log(pnorm(x))", col = "red", adj = 1)
rnorm> ## if you want the so-called 'error function'
rnorm> erf <- function(x) 2 * pnorm(x * sqrt(2)) - 1
rnorm> ## (see Abramowitz and Stegun 29.2.29)
rnorm> ## and the so-called 'complementary error function'
rnorm> erfc <- function(x) 2 * pnorm(x * sqrt(2), lower = FALSE)
rnorm> ## and the inverses
rnorm> erfinv <- function (x) qnorm((1 + x)/2)/sqrt(2)
rnorm> erfcinv <- function (x) qnorm(x/2, lower = FALSE)/sqrt(2)
If we are not sure about the name of the function, we can search using the apropos
function:
[1] "psmirnov" "qsmirnov" "rnorm" "rsmirnov"
[1] "dlnorm" "dnorm" "norm" "normalizePath"
[5] "plnorm" "pnorm" "qlnorm" "qnorm"
[9] "qqnorm" "rlnorm" "rnorm"
Note: You can even use regular expressions in the search string.
The find()
function tells what package a function is in, for instance:
Many R packages also have vignettes (more detailed descriptions on how the packages work).
To List vignettes from loaded (attached packages):
To list vignettes from all installed packages:
A friendlier option is:
If you know the name of the vignette use:
The R manuals
Go to https://cran.r-project.org/ and select Manuals
on the left bar.
The R forums and lists
RStudio Community is a friendly forum to ask questions about R and RStudio.
R also has a user list, to search it go to https://cran.r-project.org/ and select Search
Notes: You can also use RSiteSearch("rnorm")
from the R console
The trick to search google is to add “in R”, or just “R” after the search term:
Go to https://google.com
and try searching for random normal numbers in r
Other good sources for help are:
Before asking a question make sure that you have:
Be sure to provided a reproducible example.
For more on this take a look at:
Rstudio provides a wide selection of cheatsheets which contain excellent information, particularly when starting out:
Try to do the exercises below.