Last active
February 12, 2019 14:00
-
-
Save cormac-work/2eb02d4fbd22a37d0097eb1a01869385 to your computer and use it in GitHub Desktop.
R Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# R Snippets | |
## How to use this file | |
Just open the file and search for key term. Or you can browse by heading (# or ##) | |
## Tables | |
To make a table: | |
Table is a function that produces a column or row wise table that counts the number of observations across two variables. | |
Variable one will be a row (1st or horizontal dimension) and variable 2 will be the columns (2nd or vertical dimension). | |
table(dataset$Variable_1, dataset$Variable_2) | |
prop.table(table(train$Sex, train$Survived),1) | |
## Simple plot | |
# Plot data | |
plot(x = age, | |
y = exp, | |
xlim = c(20, 50), | |
ylim = c(0, 20), | |
pch = 16, | |
col = "blue") | |
# Add id labels | |
text(x = age, | |
y = exp, | |
labels = name, | |
pos = 3, # Put labels above the points | |
cex=0.5) # Set font size | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment