Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This command will only show the number of boys baptized each year. 1 . What command would you use to extract just the counts of
This command will only show the number of boys baptized each year.
What command would you use to extract just the counts of girls baptized? Try it
Notice that the way R has printed these data is different. When we looked at the complete data frame,
we saw rows, one on each line of the display. These data are no longer structured in a table with other
variables, so they are displayed one right after another. Objects that print out in this way are called vectors;
they represent a set of numbers. R has added numbers in brackets along the left side of the printout to
indicate locations within the vector. For example, follows indicating that is the first entry in
the vector. And if starts a line, then that would mean the first number on that line would represent the
rd entry in the vector.
R has some powerful functions for making graphics. We can create a simple plot of the number of girls
baptized per year with the command
plotx arbuthnot$year, y arbuthnot$girls
By default, R creates a scatterplot with each xy pair indicated by an open circle. The plot itself should
appear under the Plots tab of the lower right panel of RStudio. Notice that the command above again looks
like a function, this time with two arguments separated by a comma. The first argument in the plot function
specifies the variable for the xaxis and the second for the yaxis. If we wanted to connect the data points
with lines, we could add a third argument, the letter l for line.
plotx arbuthnot$year, y arbuthnot$girls, type l
You might wonder how you are supposed to know that it was possible to add that third argument. Thankfully,
R documents all of its functions extensively. To read what a function does and learn the arguments that are
available to you, just type in a question mark followed by the name of the function that youre interested in
Try the following.
plot
Notice that the help file replaces the plot in the lower right panel. You can toggle between plots and help
files using the tabs at the top of that panel.
Is there an apparent trend in the number of girls baptized over the years?
How would you describe it
Now, suppose we want to plot the total number of baptisms. To compute this, we could use the fact that R
is really just a big calculator. We can type in mathematical expressions like
to see the total number of baptisms in We could repeat this once for each year, but there is a faster
way. If we add the vector for baptisms for boys and girls, R will compute all sums simultaneously.
arbuthnot$boys arbuthnot$girls
What you will see are numbers in that packed display, because we arent looking at a data frame here
each one representing the sum were after. Take a look at a few of them and verify that they are right.
Therefore, we can make a plot of the total number of baptisms per year with the command
plotarbuthnot$year, arbuthnot$boys arbuthnot$girls, type l
This time, note that we left out the names of the first two arguments. We can do this because the help file
shows that the default for plot is for the first argument to be the xvariable and the second argument to
be the yvariable. Similarly to how we computed the proportion of boys, we can compute the ratio of the
number of boys to the number of girls baptized in with
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started