Data Types Flashcards

1
Q

getwd()

A

Returns the current working directory

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

setwd()

A

sets the current working directory

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

source()

A

loads the contents of a file

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

ls()

A

lists objects in a given workspace

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

dir()

A

lists files in the current working directory

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

What happens when you try to include elements of multiple classes in a vector?

A

Certain elements are “coerced”, such that the class of that element is changed to a different type

This can have unexpected results

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

What object can contain elements of different classes?

A

A list

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

What are two functions used to create vectors, and what are their differences?

A

vector() and c()

With vector(), you have to pass a “mode” (atomic class type or “list”), and the vector length

By default c() combines its arguments to form a vector

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

How do you force a number to be represented as an integer?

A

Append an “L” to it, e.g. 1L

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

How is infinity represented in R

A

Inf

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

How is “not a number” represented in R

A

NaN

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

How are missing values represented in R?

A

NA

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

What is a set of instructions typed at the R prompt called?

A

An expression

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

What is the assignment operator?

A

<-

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

How is a string represented?

A

As a character vector

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

When you type the name of an object at the prompt and press Enter, what happens?

A

The value gets auto-printed

17
Q

How do you create a vector of integers from 1 to 10?

A

x <- 1:10

18
Q

How do you explicity coerce all elements of a vector to a given logical objects?

A

as.logical(x)

19
Q

How do you return the class of vector x?

A

class(x)

20
Q

What happens when you try to coerce a vector but certain elements cannot be coerced?

A

You get a set of NA values back

21
Q

What’s the core difference between a vector and a matrix?

A

A matrix is a vector with dimensions, specifically the “dim” attribute, a numeric vector

22
Q

How to you set the dimensions of a matrix m?

A

dim(m) <- c(1, 2)

23
Q

How do you return all attributes of a vector x?

A

attributes(x)

24
Q

Are matrices constructed column-wise or row-wise?

A

column-wise

25
Q

What’s a simple way to create a matrix from an existing vector?

A

x <- c(2, 2)

26
Q

What are factors?

A

factors are a special type of vector used to represent categorical data

factors can be ordered or unordered

treated specially by modelling functions

really an integer vector with a “levels” attribute

27
Q

How do you create factors?

A

x <- factor(c(“yes”, “no”))

28
Q

How do you order factors?

A

passing the “levels” argument, which is a character vector that specifies the ordering of the factors

29
Q

How do you find the missing elements of a vector x?

A

is.na(x)

30
Q

What are data frames?

A

a special type of list, where every element of the list has to have the same length

each element of the list here can be thought of as a column

length of each element is the number of rows

have special attributes called row.names

31
Q

What two functions are traditionally used to load data from disk and into a data frame?

A

read.table() and read.csv()

32
Q

How do you apply names to a standard, atomic object?

A

x <- 1:3
names(x) <- c(“foo”, “bar”, “baz”)

33
Q

How do you use cbind/rbind, and how do they work?

A

cbind(x, y) ; cbind binds vectors by column

rbind(x, y) ; rbind binds vectors by rows

Think of gluing two vectors together vertically (cbind) or horizontally (rbind)

34
Q

What’s the difference between an object’s mode and its class?

A

‘mode’ is a mutually exclusive classification of objects according to their basic structure. The ‘atomic’ modes are numeric, complex, charcter and logical. Recursive objects have modes such as ‘list’ or ‘function’ or a few others. An object has one and only one mode.

‘class’ is a property assigned to an object that determines how generic functions operate with it. It is not a mutually exclusive classification. If an object has no specific class assigned to it, such as a simple numeric vector, it’s class is usually the same as its mode, by convention.

35
Q

What’s one benefit to using factors in R for the purpose of graphing

A

Factors are used to group data

ggplot silently coerce character vectors to factors, as does read.table with the stringsAsFactors = TRUE argument

36
Q

What are categorical variables?

A

Variables which take on a limited number of different values