1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
FRONT
BACK
What functions are used to add up the elements in rows and columns of matrices? What do these function return? Provide an example of adding up a matrix’s rows.
rowSums()
colSums()
These functions return a vector with the sums
rowSums(matrix)
How do you check a variable’s data type?
class()
Can vectors store multiple vectors?
No
FIRST PASS
FIRST PASS
SECOND PASS
SECOND PASS
How to do exponentiation?
x ^ x
What is modulo and how do you do it?
Returns division remainder
x %% x
How do you initialize a variable with a value?
x <- number
How do you print a variable?
x
OR
print(x)
(OR cat(x))
Numerics vs Integers
Numerics: Decimal
Integers: Whole
True/False or TRUE/FALSE
TRUE/FALSE
What is a vector?
A one dimensional array
How do you create a vector?
c(x, y, z)
How do you apply labels to vector values after initialization?
names(vector) <- c(x, y, z)
If you add two vectors, what does this do?
c(a, b, c) + c(x, y, z) = c(a + x, b + y, c + z)
How to add up all the elements in a vector?
sum(x)
How to add up a bunch of values or numerical variables without using a plus sign?
sum(x, y, z)
Can you sum numeric and integer variables together?
Yes
How many comparison operators are in R, and what are they?
There are six comparison operators in R:
x > y
x < y
x >= y
x <= y
x == y
x != y
In R, is the first element of a series of elements 0, or 1?
1
How to obtain a single cell from a vector?
vector[x]
How to obtain multiple specific cells from a vector?
vector[c(x, y, z)]
How to obtain a range of cells from a vector?
vector[x:y]
How to obtain a cell from a vector using that cell’s name?
vector[“x“]
How to obtain multiple specific cells from a vector using those cells names?
vector[c(“x”,”y”)]
How to find the mean of all the elements in a vector?
mean()
What does it return when you use a comparison operator on a vector? Ex. vector == 5
It returns a boolean vector where a comparison is done for each element in the original vector to determine if the corresponding element in the boolean vector is TRUE or FALSE
What does this return?
vector[boolean vector]
A new vector that is the part of the old vector where all the boolean values were true
Can vectors hold elements that are different data types from one another?
No
What does this return? What are their data types?
1:3
1:3.9
1.3:3.9
1 2 3
1 2 3
1.3 2.3 3.3
Vector
How do you make a matrix?
matrix()
In order, what are the arguments for a matrix?
There are 5 arguments for a matrix
1st: data
2nd: nrow
3rd: ncol
4th: byrow
5th: dimnames
For the dimnames argument of a matrix, what can you enter?
NULL or a list. The list can be input three ways. First, it can be input as empty and will become NULL. Second, as one vector, which will become the row names. Third, as two vectors, the first of which will become the row names and the second of which will become the column names.
What is the byrow argument for the matrix?
byrow determines if the data is filled in by row or by columns
What are the ways you can enter data into a matrix?
One variable with all the data, or one variable with enough variables to fill the rows and columns
What functions are used to name the rows and columns of matrices after the matrix’s creation? Provide an example of naming a matrix’s rows.
rownames()
colnames()
rownames(matrix) <- row_names_vector
What functions are used to combine vectors and matrices by rows and columns? Provide an example of combining two matrices.
rbind()
cbind()
matrix3 <- rbind(matrix1, matrix2)
What is the workspace in R?
All of the currently user-defined objects
How do you display all of the objects in the workspace?
ls()
How to obtain a single cell from a matrix?
matrix[x, y]
How to obtain a smaller matrix from a matrix?
matrix[x:y, a:b]
How to obtain all the elements from a row or column of a matrix?
Whatever parameter inside of the brackets that are left blank will have everything inside selected.
Ex: matrix[1,]
What happens when you apply a standard operator to a matrix? Ex. matrix * 2
Applies the calculation to all elements of the matrix
What happens when you apply a standard operator to two matrices? Ex. matrix1 * matrix2
Takes each same cell of both matrices, and does the calculation between them