3.10 Chapter Quiz

  1. What are the four common types of atomic vectors? What are the two rare types?
Answer(s) The four common types of atomic vector are logical, integer, double and character. The two rarer types are complex and raw.
  1. What are attributes? How do you get them and set them?
Answer(s) Attributes allow you to associate arbitrary additional metadata to any object. You can get and set individual attributes with attr(x, "y") and attr(x, "y") <- value; or you can get and set all attributes at once with attributes().
  1. How is a list different from an atomic vector? How is a matrix different from a data frame?
Answer(s) The elements of a list can be any type (even a list); the elements of an atomic vector are all of the same type. Similarly, every element of a matrix must be the same type; in a data frame, different columns can have different types.
  1. Can you have a list that is a matrix? Can a data frame have a column that is a matrix?
Answer(s) You can make a list-array by assigning dimensions to a list. You can make a matrix a column of a data frame with df$x <- matrix(), or by using I() when creating a new data frame data.frame(x = I(matrix())).
  1. How do tibbles behave differently from data frames?
Answer(s) Tibbles have an enhanced print method, never coerce strings to factors, and provide stricter subsetting methods.