R Code Cheat Sheet



R programming Codes Cheat Sheet by deleted - Cheatography.com Created Date: 1548Z. The examples use the traditional built-in R data sets (such as the iris data, used to create the neural network above), so there's unfortunately not much of a “big data” aspect to the reference card. But if you're just getting started with prediction and classification models in R, this cheat sheet is a useful guide.

  1. R Code Cheat Sheet
  2. Basic R Syntax Cheat Sheet

How to use chmod codes in UNIX:

  1. There are three types of permissions in files and folders in unix
    1. Read (r)
    2. Write (w)
    3. Execute (x)
  2. And, there is a classification of users called UGO (explained bellow):
    1. U ~> User (usually, you)
    2. G ~> Group (eg sudo group)
    3. O ~> Others

When you run $ ls -l your output will be something like this:

How to read this?

Where is a letter put a 1 and where is a - put a 0. Examples:

UGO
r w xr w xr w x
1 1 11 1 11 1 1

So, user, group and others can read, write and excute the file or folder

UGO
r w -r --r - x
1 1 01 0 01 0 1

So, user can read and write, group can only read, finally other can read and execute

As you can see, we can play with these permissions

UGO
r - xr w -- - -
1 0 11 1 00 0 0
UGO
- w xr - x- - x
0 1 11 0 10 0 1

Finally, the codes! (sorry)

BinDecimalRepresentation
0000- - -
0011- - x
0102- w -
0113- w x
1004r - -
1015r - x
1106r w -
1117r w x

The syntax is something like this: $ chmod u/permissions g/permissions o/permissions file[or /dir/]

  • So, if I run $ chmod 777 file <=>rwx rwx rwx everybody can do anything with file
  • Or I run $ chmod 744 dir <=>rwx r-- r--only user can read, write and execute, group and others only read dir.
  • Or run $ chmod 200 file2 <=>-w- --- ---only you can write file2

Thanks for reading, I hope it works! Follow me on Twita and GitHub

Refs:

Special thanks:

  • Gabe Kutuzov (GitHub)

I reproduce some of the plots from Rstudio’s ggplot2 cheat sheet using Base R graphics. I didn’t try to pretty up these plots, but you should.

I use this dataset

The main functions that I generally use for plotting are

  • Plotting Functions
    • plot: Makes scatterplots, line plots, among other plots.
    • lines: Adds lines to an already-made plot.
    • par: Change plotting options.
    • hist: Makes a histogram.
    • boxplot: Makes a boxplot.
    • text: Adds text to an already-made plot.
    • legend: Adds a legend to an already-made plot.
    • mosaicplot: Makes a mosaic plot.
    • barplot: Makes a bar plot.
    • jitter: Adds a small value to data (so points don’t overlap on a plot).
    • rug: Adds a rugplot to an already-made plot.
    • polygon: Adds a shape to an already-made plot.
    • points: Adds a scatterplot to an already-made plot.
    • mtext: Adds text on the edges of an already-made plot.
  • Sometimes needed to transform data (or make new data) to make appropriate plots:
    • table: Builds frequency and two-way tables.
    • density: Calculates the density.
    • loess: Calculates a smooth line.
    • predict: Predicts new values based on a model.

All of the plotting functions have arguments that control the way the plot looks. You should read about these arguments. In particular, read carefully the help page ?plot.default. Useful ones are:

  • main: This controls the title.
  • xlab, ylab: These control the x and y axis labels.
  • col: This will control the color of the lines/points/areas.
  • cex: This will control the size of points.
  • pch: The type of point (circle, dot, triangle, etc…)
  • lwd: Line width.
  • lty: Line type (solid, dashed, dotted, etc…).

Discrete

R Code Cheat Sheet

Barplot

Different type of bar plot

Continuous X, Continuous Y

Scatterplot

Basic R Syntax Cheat Sheet

Jitter points to account for overlaying points.

Add a rug plot

Add a Loess Smoother

Loess smoother with upper and lower 95% confidence bands

Loess smoother with upper and lower 95% confidence bands and that fancy shading from ggplot2.

Add text to a plot

Discrete X, Discrete Y

Mosaic Plot

Color code a scatterplot by a categorical variable and add a legend.

Code

par sets the graphics options, where mfrow is the parameter controling the facets.

The first line sets the new options and saves the old options in the list old_options. The last line reinstates the old options.

This R Markdown site was created with workflowr