Chapters 1&2 Flashcards
What does the rev command do in R?(1)
Reverses the order of the vector.
What does the sort command do in R?(1)
It arranges the vector into either numerical order ascending or alphabetically for character vectors.
What does the sum command do in R?(1)
Adds the vector constituents.
What does the unique command do in R?(1)
Denotes all elements of the vector which are unique ie vector_1= c(2, 3, 3, 4, 4 ,4) Unique elements would be 2, 3 ,4.
What does the which command do in R?(1)
Gives index/indices of particular elements ie which (vector_1==2) [1]=1 as only 2 in vector_1 is equal and is the first value in the vector hence is number 1.
If A is a logical vector, A=TRUE, what would !A be read as?
Read as ‘Not A’ therefore !A=FALSE.
How do you use logical vectors to extract information?(1)
By setting a logical vector and applying it to another vector you can bring out all elements of the vector to which the logical vector are true (see pg.11 notes for example).
What would happen if you summed a logical vector?(1)
It would give you the total number of true vectors.
What would happen if you summed the logic vector of another vector?(1)
It would sum the values for which have came out of the logic vector applied to the original vector.
How would you extract the xth smallest value from a vector?(1)
sort(x[x]) note different from doing sort(x) then x[97]! (Made this error in exercise 2.1
For a logical vector how would you find the xth position of true?(1)
which(y==TRUE)[xth].
Difference between dataframes, vectors and matrices in R?(1)
Vectors are 1 dimensional, Matrices and dataframes are 2 dimensional as have rows and columns
Dataframes different to matrix as matrices only numerical
What does rxc dataframe mean?(1)
Rows come before columns in dataframes in all cases.
How would you find the least used letter in a character vector?(1)
summary(as.factor(vector)) then take minimum and look to see which matches up.