The following questions ask you and your breakout group to piece together code that’s out of order. The aim is to put it in order so that the code will run without an error. To ensure you’ve put the code in the right order, try running it on your machine. We’ll join back together as a group and see what everyone came up with. Please report your answer using the letters for each code chunk, e.g., “A, D, C, B”.
The following vector contains some country names.
The code seeks to separate these country names into a
starts_with_A group and
starts_with_B group. We’ll use the first letter of each country name to figure out which group the country should be member to. If it’s not either group, store it as
Note: we’ll use a function called
substr which stands for “substring”. The function takes in a string, and returns part of it, starting at
start = and going until the
end = argument. The user provides an index
##  "George"
start = 1 and
end = 1 we are calling the first letter of each country name.
The following code uses the
sleep dataset (which comes built into
## extra group ID ## 1 0.7 1 1 ## 2 -1.6 1 2 ## 3 -0.2 1 3
## extra group ID ## 18 1.6 2 8 ## 19 4.6 2 9 ## 20 3.4 2 10
The data records the effect of two soporific drugs (increase in hours of sleep compared to control) on 10 patients in each group. The following code calculates the average increased hours of sleep by group and stores it into a new data frame called