R/Python Coding Cheatsheet
This cheatsheet is intended as a quick reference you can use to “translate” between concepts from the course and the functions/libraries which implement these concepts in both R and Python. Use the search box below (not the one in the page sidebar) to filter all of the rows down to the particular concepts, or the particular functions, that you are looking for.
I strongly recommend viewing this on your laptop (that is, in a full-screen-width browser) rather than on mobile, since I’ve made the page width wider here to make room for the blocks of code within each column!
Concept | R Code | Python Code |
---|---|---|
Bernoulli Distribution |
Using Base R:
|
Using SciPy:
|
Continuous Uniform Distribution |
Using Base R:
|
Using NumPy:
|
Discrete Uniform Distribution |
Using the
|
Using NumPy:
|
Normal Distribution |
Using Base R:
|
Using NumPy:
|
Add a new column to a data table |
Using Tidyverse:
|
Using Pandas:
|
Download a .csv file from a URL
|
Using the
|
Using the
|
Generate a data table from a set of columns |
Using Tidyverse:
|
Using Pandas:
|
Generate a data table quickly by entering values in your code |
Using Tidyverse:
|
Using Pandas:
|
Generate sequence from 1 to N
|
In steps of size 1:
In steps of size
|
In steps of size 1:
|
Sample N rows from a data table (chosen uniformly at random, without replacement)
|
Using Tidyverse:
|
Using Pandas:
|
Scatterplot |
Using
x_var_name and y_var_name are the names of columns within df .
|
Using Seaborn:
x_var_name and y_var_name are the names of columns within df .
|
Subset columns of a data table by column name |
Using Tidyverse:
col1_name and col2_name within df
|
Using Pandas:
col1_name and col2_name within df . (We use .copy() at the end so that this produces a new DataFrame object containing just these columns. Otherwise, this operation just returns a pointer to a subset of the original DataFrame object)
|
Subset rows of a data table by value |
Using Tidyverse:
df for which the value in the column called col_name is col_value
|
Using Pandas:
df for which the value in the column called col_name is col_value
|