Basics in R Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Simple calculations

A

> 5 + 3

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

Variable assignment

A

> age < - 28

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

Using existing functions for calculations

A

> sqrt (225)

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

Creating a vector

A

> weekly_sales < - c(200, 120, 130, 125, 220)

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

Getting information out of a vector

A

> weekly_sales{3}

> weekly_sales{weekly_sales > 180}

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

Installing packages

A

> install.packages(“somepackage”)

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

Loading packages

A

> library(“somepackage”)

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

Setting working directory

A

> setwd(“~/myDirectory”)

To get the symbol, Alt 126

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

Reading a csv file

A

> data < - read.csv(“somedata.csv”)

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

Get the structure of the object

A

> str(data)

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

Get the head of the object

A

> head(data)

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

Get the names of the object

A

> names(data)

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

Get the entire object

A

> data

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

Calculate the mean of a variable

A

> mean(data$someVariable)

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

Calculate the median of a variable

A

> median(data$someVariable)

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

Estimate the population variance of a variable

A

> var(data$someVariable)

17
Q

Estimate the population standard deviation of a variable

A

> sd(data$someVariable)

18
Q

Get an overall summary of an object or a variable

A

> summary(data)

> summary(data$someVariable)

19
Q

Calculate descriptive statistics separately for each group

A

> by(data, data$someVariable, summary)

20
Q

Plot a variable (the type of graph generated depends on the type of variable)

A

> plot(data$someVariable)

21
Q

Draw a histogram for some variable

A

> hist(data$someVariable))

22
Q

Draw a boxplot for some variable

A

> boxplot(data$someVariable)

23
Q

Draw a bar chart for some variable

A

> freq < - table(data$someVariable)

> barplot(freq)

24
Q

Draw a pie chart for some variable

A

> freq < - table(data$someVariable)

> pie(freq)

25
Q

Draw a scatterplot for two variables

A

> plot(data$variable1, data$variable2)