As the name implies, this is to give you extra R practice, especially if you finish your lab early. First part will walk you through some basic functions dealing with Orange trees.
    By the way, an interesting thing R has going for it is that it already has some data sets pre-packaged for you to use without having to find the data from an external source. This can be useful for small things in R (like this) and it can also be very useful if, say, you are interviewing for a stats position and you need to make sure the students have access to the data (not saying it got me this job but it was a strategic decision made during my interview prep lol).

# Orange Trees

```{r}
#First, let's look at the data sets we can pull as we like
data() #brings up the data set list R already has
data("Orange") #and loads the Orange tree data
Orange
```
0) Look at the data sets R has available by running data() on your machine and note if any look interesting to you; and if they don't look interesting what looks the least boring?

1) Using the help page for Orange, what is the unit of measurements for age? Circumference? 

2) How many trees are in the data? 

3) Check the class of Tree variable and report what it says HINT: One of the functions that can do this is in lab 1 AND there should be two different classes reported

4) Calculate the mean circumference of all observations

5) Using subsetting, calculate the mean circumference of the trees in the data set on the last day each tree was recorded. Hint: For each tree, fine the row for which it is the oldest and use those rows to calculate the mean circumference. Comment on the discrepancies in the two means and why that might be.

6) Assuming that tree trunks are cylinders (....meh), calculate the diameter of each observation. Hint: circumference = 2pi*radius and diameter = 2 radius. Also note that arithmetic functions can be applied to all entries in a vector simultaneously. Eg see what happens when you run c(1,2,6) + 2

7) Which observation has the minimum circumference? Do NOT just scan the data to find it. Try to use a function to do it for you; remember you can search the help pages using ??STUFF as needed (replace STUFF with the word you want to search for). For that observation, report the age of the tree.
   Hint: in the search pages the first word on the left is the package the function is from and usually indicates what the function deals with. Eg stuff that starts with "igraph" probably have something to do with graphics which isn't what you want. 

8) Using the orange tree data set, make a new data frame but with the columns in the order of (Tree, Circumference, Age). There are several ways to do this, some require less writing than others. HINT: Some helpful funcitons might be subsetting or the data.frame() function

# Enough with trees already

9) Let's check how many calculations your machine can do before it bogs down. To do this run the following script and slowly increase the simulation count. Continue to do so until your computer takes more than five seconds to generate the random simulations and calculate the mean. My machine does okay up to about 200 million observations (albeit the college gave me a pretty nice computer)
```{r}
num_of_simulations <- 10000

random_numbers <- rnorm(num_of_simulations) #this will (pseudo-) randomly generate 10,000 draws from a standard normal distribution. You can look at the first few observations of this vector by using the head() function. Ie head(random_numbers)

mean(random_numbers) #and this will calculate the mean
```

10) Sometimes large data sets (as in needing a lot of memory) can be annoying, bog things down, and you just want them gone. We can do two things. First, we use the rm(OBJECT) command to *remove* OBJECT from the enviroment and then use gc(), which stands for *garbage collection* to free up the memory the object was using. This really isn't a question but you should do it yourself to free up the memory. I also just wanted to show you for future reference
```{r}
rm(random_numbers)
gc()
```



11) Lower the number of simulations you ran in question 9 back down to 10,000. Functions in R can be nested, where one function is applied within another function. Try to do that with the above rnorm() and mean() functions. Hint: rnorm will need to be nested inside of the mean function

