Session Ready
Exercise

R - The big calculator

Suppose you want to plot the total number of births: boys and girls combined. One way to do this is by typing in the console
mathematical expressions like 1211684 + 1148715 to see the total number of births in 1940. (Try it, you'll see it works).

We could repeat this once for each year, but there is a faster way. If we add the vector for births for boys and girls, R will compute all sums simultaneously.

When adding the vectors with the births of boys and girls respectively, R will automatically take the element-wise sum. In this case, we'll get a vector with the total number of births per year.

Adding columns of a data frame is simple, since they have the same length by definition:

data_frame$variable_name_1 
  + data_frame$variable_name_2 
  + ...
Instructions
100 XP
  • Create a new vector with the name babies that is equal to the sum of the number of births for boys and girls respectively.
  • Make a simple line plot of the total number of births as a function of time. Be inspired by the previous exercises where you did something similar for boys and girls separately.