Home
61.
How would you count the number of times the word “thou” appears in Shakespeare’s The Tempest?

Read in the text as a character vector wih readLines, call str_count to count the number of instances in each line, and sum the total.

62.
Name as many functions as you can think of for adding columns to data frames.

with, within, transform, and mutate all allow manipulating columns and adding columns to data frames, as well as standard assignment.

63.
What is the opposite of melting?

Casting. Not freezing!

64.
How would you reorder a data frame by one if its columns?

Use order or arrange.

65.
How would you find the first positive number in a vector?

Define a function that reads TRUE when you have a positive number—for example, is.positive <- function(x) x > 0—and call Find(is.positive, x).

66.
What is the difference between the min and pmin functions?

min returns the single smallest value of all its inputs. pmin accepts several vectors that are the same length, and returns the smallest at each point along them.

67.
How would you change the shape of the points in a base plot?

Pass the pch (“plot character”) argument.

68.
How do you specify the x and y variables in a lattice plot?

Use a formula of the form y ~ x.

69.
What is a ggplot2 aesthetic?

An aesthetic specifies a variable that you will look at a variation in. Most plots take an x and a y aesthetic for x and y coordinates, respectively. You can also specify color aesthetics or shape aesthetics (where more than two variables are to be looked at at once, for example).

70.
Name as many plot types as you can think of for exploring the distribution of a continuous variable.

Histograms, box plots, and kernel density plots were all mentioned in the chapter. There are some other weirdly esoteric plots, like violin plots, rug plots, bean plots, and stem-and-leaf plots, that weren’t mentioned. Have 100 geek points for each of these that you guessed.