TalkingQuickly's Today I Learned

3 posts about #data-science

R Packages

Install R packages with:

install.packages("tidyverse")

Load them for use at runtime with:

library(tidyverse)

Tidyverse is a collection of packages for R which seem to be widely referenced as well written R code (https://www.tidyverse.org/). They're used extensively in the excellent book R for Data Scientists https://r4ds.had.co.nz

Really Basic R Concepts

For assignment should always use <- rather than =

Can use class(VAR) to get the type of an object

R functions allow both positional and name based matching. So class(5) and class(x=5) are both valid invocations, class(y=5) is not because class does not have an argument named y. Default arguments for functions are supported.

Use ?method for docs, e.g. ?class. Running this in RStdudio triggers a wonderful bit of magic where docs are displayed in the output panel rather than the console.

Great overview: https://cecilialee.github.io/blog/2017/12/05/intro-to-r-programming.html

R has lots of built in example data sets

The package datasets contains a selection of example datasets which can be used for testing out and playing with R functions.

You can get a list of all available datasets by running data() in a console. Each dataset is available by default in a variable the name of which is outputted in data(), e.g. AirPassengers or cars.

A summary of the data can be generated using the R function summary, e.g. summary(cars).

More: https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/00Index.html

and: http://www.sthda.com/english/wiki/r-built-in-data-sets