learn 

Send to Kindle
home » snippets » r » learn


Pages
graphs        
matrix        
vectors        



Notes

Sourcing code from a file.

source("file.R")

Listing a directory – list.files()

> list.files()
 [1] "_dotfiles"        "Applications"     "bin"[19] "install"          "lib"              "Library"

Vectors

See R/vectors

Functions

You can use help(function) and example(function) to get help / examples about a function.

sum function.

This function takes a variable number of arguments (and a keyword argument, na.rm = FALSE that's not covered here.)

> sum(1, 2, 3, 4, 5)
[1] 15
> sum(1:5)
[1] 15

# You can pass vectors as individual arguments too.
sum(1:3, 1:4)
[1] 16
# Or mix vectors and scalars.
> sum(1:3, 4, 1:4)
[1] 20