Intro to R Flashcards

1
Q

Install packages

A

install.packages(“packagename”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Load packages

A

library(packagename)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Set working directory

A

setwd(location)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Load data from computer

A

read.csv(“filename”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Load pre-assigned dataset

A

data(“filename”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Select specific value

A

select(filename, row, column)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Summary statistics

A

summary(datafile).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

See specific rows

A

head(datafile, #)
tail(datafile, #)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Omit NA values

A

na.omit(datafile)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Remove columns

A

dplyr::select(dataset, -contains(“colname”))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Filter values

A

filter(datafile, col <= #)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Histogram

A

hist(dataset$col)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Create new column/mutate using a formula

A

dataset %>% mutate (newcolname= (formula))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Determine if columns are identical

A

identical(dataset$col1, dataset$col2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Save data as CSV

A

write.csv(newname)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

returns the number of columns in the dataset

A

ncol(datafile)

17
Q

returns the number of rows in the dataset

A

nrow(datafile)

18
Q

returns the names of the columns

A

colnames(datafile)

19
Q

provides information about the data types of the columns

A

str(datafile)

20
Q

Replicability

A

the ability to recreate your results using a different dataset

21
Q

Reproducibility

A

the ability to recreate you results using the same dataset

22
Q

IDE

A

Integrated development environmen (r-studio)

23
Q

Packages

A

extensions of the r-lanuage that allow you to run additional functions

R comes with built-in functions, but if you want to do functions outside that pre-set, you can download packages

24
Q

Clean code

A

making your code easy to understand and consistent, and therefore reusable

25
Q

7 tenets of clean code

A

Meaningful Variable and Function Names: each name of the variable or function should convey a purpose, do not make it vague

Modularization: If the script is too long, break up so its easier to understand

Consistent Formatting: Choose a style and stick to it

Comments and Documentation: explain what and why you did

Avoid Magic Numbers and Hard Coding: Don’t use unexplained numeric values, assign them to a constant/a variable name

Avoid Duplicate Code.

The Single Responsibility Principle (SRP): Each script should have one clear purpose or responsibility