This is the first in-class computing task for the course. These instructions apply to this and future computing tasks.
.Rmd document that lives in your individual math253-<your name> repository. The document for today is called 01-Programming.Rmd. Upcoming days’ work will involve files named in the same fashion.When you are finished with your work, you will compile the .Rmd file to HTML. The compilation must run to completion when you “source” it. That is, you should be able to see the resulting HTML file.
task3. Make sure to use this name exactly, including capitalization. If you don’t, the scoring system will miss your answer.To help you keep track of your answers, use subsection headings to divide your .Rmd file, like this:
## Task 3At the end of the class, stage the documents you’ve changed (including the HTML document), commit, and push to GitHub
Before we start, you will need to install on your RStudio system a package that provides tests for your document, so that you can see what commands are not yet right. Here’s the command to install the package, which you need do only once.
These are meant to help you learn some basics in R. Don’t expect the answers to be immediately evident to you.
There is a package called mosaicData. Write the command that will load this package into R. Note that load() is (surprisingly) not the correct function to do this.
You may find that mosaicData is not yet installed on your R system. If not, use the Packages tab in RStudio to install it. This is done outside of your script. Once installed, a package can be used in any script you like without re-installation.
Create an object named task2 that contains a character string like “Today is Tue Sep 20 07:15:57 2016”. Your command should be such as to create a string with the correct date on any day in the future that the document is compiled.
You will find two functions to be useful:
paste(), which concatenates strings.now(), today(), day_time(), day(), time(), date_time(), date(), at_present(), clock(), calendar().In the mosaicData package, there is a data frame named Galton. Create these objects:
task3a containing the names of the variables in Galtontask3b containing the number of cases in Galtontask3c containing the mean of height in GaltonCreate an object task4 containing the following object:
\[ \left( \begin{array}{ccc} 1 & 2 & 3\\ 4 & 5 & 6\\ \end{array} \right) \]
Hint: the object is a matrix.
1000 random points uniformly distributed in the unit square in the first quadrant. The unit circle is shown for comparison.
Create these objects:
task5x a vector with 1000 random values between 0 and 1. (Hint: runif())task5y another such vector.task5pi the value of \(\pi\) estimated from a “Monte Carlo” simulation. That is, for each of task5x and task5y, square the vector. Then add them together and take the square root. This will give the length from the origin to each of 1000 random points in the unit square in the first quadrant. Finally, compute what fraction of these lengths are \(\leq 1\). That fraction is an estimate of \(\pi / 4\).