Answered step by step
Verified Expert Solution
Link Copied!

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.
1. 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 82 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, 5218 follows [1], indicating that 5218 is the first entry in
the vector. And if [43] starts a line, then that would mean the first number on that line would represent the
43rd 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
plot(x = arbuthnot$year, y = arbuthnot$girls)
By default, R creates a scatterplot with each x,y 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 x-axis and the second for the y-axis. If we wanted to connect the data points
with lines, we could add a third argument, the letter l for line.
plot(x = 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.
2. 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
5218+4683
to see the total number of baptisms in 1629. 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 82 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
plot(arbuthnot$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 x-variable and the second argument to
be the y-variable. 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 1629 with
3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Coping with competitive pressure and sport performance anxiety

Answered: 1 week ago

Question

What perspective or approach to talent would be appropriate?

Answered: 1 week ago

Question

What policies and practices for talent development are needed now?

Answered: 1 week ago