1.1.1 Flashcards

(42 cards)

1
Q

What does the function library() do?

A

Loads packages

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

What function reads data into R?

A

read_csv(“”)

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

What does head() do?

A

Shows the first six rows of data by default

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

What does the function head(data, n = x) do?

A

Changes the number of rows displayed in head()

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

What is the function dim() used for?

A

Looking at how big the data is

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

What do the left and right number represent in the output of dim()?

A

Left = rows
Right = columns

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

What are observational units?

A

Individual entities on which data are collected (normally rows)

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

What are variables?

A

Any characteristic that varies between observational units (usually columns)

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

What does the dollar sign $ allow us to do?

A

Extract a specific variable from a dataframe

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

What is a vector?

A

Each variable in a dataframe

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

What are the square brackets [] used for?

A

Indexing (finding specific entries in the data)

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

What functions are used to find specific values in vectors and dataframes?

A

Use vector[entry] for vectors/single sequence of values
Use dataframe[rows, columns] for dataframes

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

What happens if we leave either rows or columns blank in the dataframe[rows, columns] function?

A

We will get out all of them

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

How can we identify a column using quotation marks?

A

dataframe[“column name”]

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

How can we combine multiple rows/columns using the combine function?

A

Dataframe[c(n1,n2), c(n3,n4)]

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

What function allows us to specify a sequence?

A

Colon from:to:

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

How can we combine the $ and [] function?

A

Dataframe$variable[row/column/vector]

18
Q

What are conditions?

A

Conditions e.g. > or == allow us to access entries of data for which the condition is true
e.g.
somevalues[somevalues > 20]
starwars[starwars2$species == “Droid”, ]

19
Q

What is the with() function and an example of using it?

A

A function that creates a container where variables of a data frame are available without the need to use $
e.g.
with(starwars2, starwars2[species == “Droid”, ]

20
Q

What is data cleaning?

A

Identifying incorrect/incomplete/irrelevant data
Replacing/modifying/deleting them

21
Q

How can we replace/overwrite/reassign parts of the data? Give an example

A

dataframe[row, column] <- “entry”
e.g.
starwars2[2,6] <- “Droid”

22
Q

How can we assign selected entries to a new value? Give an example

A

Dataframe[dataframe$column==”entry”, “column name/number”] <- “entry”
e.g.
starwars2[starwars2$homeworld==”Naboo”, “species”] <- “Nabooian”
OR
starwars2$species[starwars2$homeworld==”Naboo”] <- “Nabooian”

23
Q

How can we rewrite existing columns or add new columns in a dataframe, and what are 2 examples?

A

Dataframe$entry <- dataframe$entry / or * or + or – n
Dataframe$entry2 <- dataframe$entry / or * or + or – n
e.g. starwars2$height <- starwars2$height / 100 or starwars2$height2 <- starwars2$height / 100

24
Q

How can we remove rows/columns from dataframes and what is an example?

A

dataframe <- dataframe[-row(s)/space, column(s)/space]
e.g.
starwars2[-c(35, 75),]

25
What are categorical variables and levels?
Categorical variables = tell us what group/character each individual belongs to Level = each distinct group/category
26
What are nominal variables?
Unordered categorical variables with no intrinsic ordering among levels
27
What are ordinal variables?
Categorical variables which levels possess some kind of order
28
What are binary categorical variables?
Categorical variables with only 2 possible levels e.g. yes or no
29
What are numerical/quantitative variables
Variables consisting of numbers that represent a measurable quantity
30
What are continuous numerical variables?
Variables which can take any real number within the specified range of measurement e.g. height
31
What are discrete numerical variables?
Variables which can only take integer number values e.g. number of siblings
32
Why do we need to tell R explicitly what type of data each variable is?
Different types of data get treated differently by functions
33
If data is neither numerical or categorical, what does it get treated as?
Characters (symbols)
34
How are categorical types of data set and checked in R?
Set as: as.factor() or factor() Check is: is.factor(dataframe$entry)
35
How are ordinal types of data set and checked in R?
Set as: as.ordered() or factor(... , ordered = TRUE) Check is: is.ordered(dataframe$entry)
36
How are continuous types of data set and checked in R?
Set as: as. numeric() Check is: is.numeric(dataframe$entry)
37
How are character types of data set and checked in R?
Set as: as.character() Check is: is.character(dataframe$entry)
38
What does the function 'class' do and how can we use it?
Check what type of data each entry is e.g. class(dataframe$entry)
39
How can we modify the class of a variable and what is an example?
dataframe$entry <- as/class(dataframe$entry) e.g. starwars2$species <- as.factor(starwars2$species)
40
What does != and ! mean in R?
!= means “is not equal to” ! means “not”
41
What do <, <=, >, and >= mean in R?
< means less than <= means less than or equal to > means greater than >= means greater than or equal to
42
What does the function levels() do?
See the possible response options of a factor (categorical) variable