 # R Programming Problems

## Question

## Efficiency

a. Install and load the `multcomp` package, to allow testing for statistically significant differences in function timings

In this problem, you will work with the “cleaned” version of the US News and World Report data on colleges and universities, which you created in Homework 9.

b. Read the data into R.

Use the following code to change spaces in column names into periods. Change the name of the data frame to match what you called the data frame when you read it into R.

names(usnews) = make.names(names(usnews))

Write a function using a method of your choice to determine how many schools have a per-student instructional expenditure (`Instructional.expenditure.per.student`) higher than their out-of-state tuition (`Out.of.state.tuition`).
- Your function for this part of the problem should not use control flow.
- Functions from `dplyr` may be useful here.
- Alternatively, the built-in functions `length` and `which` may be useful.

Run the function.

c. Write a function using control flow to determine how many schools have a per-student instructional expenditure higher than their out-of-state tuition.

Run the function and check that you get the same answer as in part b.

d. Use `microbenchmark` to compare the running times of the two methods you wrote in parts b and c.

- **Write 1-2 sentences** answering the following: Is there a significant difference in the running times of the two methods? If so, which is more efficient?

e. Make a boxplot showing the timing comparison of the two methods.

## Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

## Efficiency

a. Install and load the `multcomp` package, to allow testing for statistically significant differences in function timings.
#install.packages("multcomp")
```{r}
library(multcomp)
library(dplyr)
library(microbenchmark)
library(ggformula)
```
In this problem, you will work with the “cleaned” version of the US News and World Report data on colleges and universities, which you created in Homework 9.

b. Read the data into R.

```{r}
```
Use the following code to change spaces in column names into periods. Change the name of the data frame to match what you called the data frame when you read it into R.
```{r}
names(usnews) = make.names(names(usnews))
```

Write a function using a method of your choice to determine how many schools have a per-student instructional expenditure (`Instructional.expenditure.per.student`) higher than their out-of-state tuition (`Out.of.state.tuition`).
- Your function for this part of the problem should not use control flow.
- Functions from `dplyr` may be useful here.
- Alternatively, the built-in functions `length` and `which` may be useful.

```{r}
f1 <- function(usnews) {
usnews %>%
filter(Instructional.expenditure.per.student>Out.of.state.tuition) %>%
summarise(n=n())
}...
\$22.50 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Programming (Dynamic, Linear, Non-linear, etc.) Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.