Data Types Flashcards
(36 cards)
getwd()
Returns the current working directory
setwd()
sets the current working directory
source()
loads the contents of a file
ls()
lists objects in a given workspace
dir()
lists files in the current working directory
What happens when you try to include elements of multiple classes in a vector?
Certain elements are “coerced”, such that the class of that element is changed to a different type
This can have unexpected results
What object can contain elements of different classes?
A list
What are two functions used to create vectors, and what are their differences?
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 do you force a number to be represented as an integer?
Append an “L” to it, e.g. 1L
How is infinity represented in R
Inf
How is “not a number” represented in R
NaN
How are missing values represented in R?
NA
What is a set of instructions typed at the R prompt called?
An expression
What is the assignment operator?
<-
How is a string represented?
As a character vector
When you type the name of an object at the prompt and press Enter, what happens?
The value gets auto-printed
How do you create a vector of integers from 1 to 10?
x <- 1:10
How do you explicity coerce all elements of a vector to a given logical objects?
as.logical(x)
How do you return the class of vector x?
class(x)
What happens when you try to coerce a vector but certain elements cannot be coerced?
You get a set of NA values back
What’s the core difference between a vector and a matrix?
A matrix is a vector with dimensions, specifically the “dim” attribute, a numeric vector
How to you set the dimensions of a matrix m?
dim(m) <- c(1, 2)
How do you return all attributes of a vector x?
attributes(x)
Are matrices constructed column-wise or row-wise?
column-wise