# Introduction Please complete the following tasks regarding the dat...

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

output:
pdf_document: default
html_document: default
word_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk\$set(echo = TRUE)
library(tidyverse)
library(knitr)
library(ggpubr)
library(boot)
```

## Introduction

Please complete the following tasks regarding the data in R. Please generate a solution document in R markdown and upload the .Rmd document and a rendered .doc, .docx, or .pdf document. Your work should be based on the data's being in the same folder as the .Rmd file. Please turn in your work on Canvas. Your solution document should have your answers to the questions and should display the requested plots.

These questions were rendered in R markdown through RStudio (<https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf>, <http://rmarkdown.rstudio.com> ).

## Question 1

The precipitation data in "precip.txt" are precipitation values for Boulder, CO from
https://www.esrl.noaa.gov/psd/boulder/Boulder.mm.precip.html.
Precipitation includes rain, snow, and hail. Snow/ice water amounts are either directly measured or a ratio of 1/10 applied for inches of snow to water equivalent. The symbol "Tr" represents a trace amount of precipitation. Observations marked by a "*" were made at a non-standard site.

In this question, you will read in the data from "precip.txt" and format it. In the formatting steps, the string manipulation commands in the "stringr"" package, part of "tidyverse" may be helpful. The functions "str_to_lower", "str_detect", "str_replace", and "str_replace_all" are particularly relevant. The dplyr function "mutate _all" may be useful.

This problem is intended as practice in light-duty data formatting. Ordinarily, one would examine the data, decide what formatting needed to be done, carry out the formatting, then use the data in analyses. For educational purposes, the problem directs you through several formatting steps. The data for the remaining problems will be provided separately to enable you to work on those before completing question 1.

The code provided below reads in the precipitation data. The values are tab-separated.Most columns are assigned the string class.

```{r}

```

## Question 1

### 1a. (1 point)

Replace all column names with all lower case versions. For example, "TOTAL" becomes "total". Please use a function to do this. Note that the names of a data frame dat can be accessed and modified using the names(dat) syntax. Verify that the reformatting succeeded by outputting the names of the columns using the command "names(dat)".

```{r}
n <- names(dat)
n <- sapply(n, tolower)
names(dat) <- n
print(names(dat))
```

### 1b. (1 point)

Replace all occurrences of "Tr" with 0. Verify that this was successful by running the command "sum(str_detect(unlist(dat),"Tr"))".

```{r}
dat[dat == "Tr"] <- 0
sum(str_detect(unlist(dat),"Tr"))
```

## 1c. (2 points)

Make a boolean vector that indicates which rows have at least one "\*". Then remove all "\*"s in "dat". Note that "\*" is a special character in string manipulation and must be proceeded by two back slashes to be used literally, "\\\\*". (This last instruction should be read in the rendered document, because back slashes and stars are also special characters in R markdown.) Please print out the years that include non-standard observations. Also, please verify that no "\*"s remain in the data set by running the command below.

```{r}
# sum(str_detect(unlist(dat),"\\*"))
special_char <- apply(dat, 1, FUN = function(x) {sum(str_detect(x,"\\*"))})
special_char_bool <- ifelse(special_char>0, TRUE, FALSE)
print(dat\$year[special_char_bool])
dat <- dat %>% mutate_each(funs(str_replace_all(., "\\*", "")))
sum(str_detect(unlist(dat),"\\*"))
```

### 1d. (2 points)

Set all precipitation columns to be of "numeric" class using the "as.numeric" function. Make the "year" column to be of class "integer". Please verify the success of this by running "sapply(dat,class)" and displaying the results.

Also, identify any resulting "NA" values and confirm that the "NA" categorization is correct. The only unavailable values in the dataset are in 2019. Note that "is.na" is a boolean function returning "TRUE" on "NA" values and "FALSE" otherwise.

```{r}
# sapply(dat,class)
# sum(is.na(dat))
# which(is.na(dat), arr.ind=TRUE)
year <- as.integer(dat\$year)
df1 <- as.data.frame(year)
dat <- as.data.frame(sapply(dat[,-1],as.numeric))
dat <- cbind(df1, dat)
sapply(dat,class)
sum(is.na(dat))
which(is.na(dat), arr.ind=TRUE...

By purchasing this solution you'll be able to access the following files:
Solution.docx and Solution.Rmd.

# 50% discount

Hours
Minutes
Seconds
\$70.00 \$35.00
for this solution

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

### Find A Tutor

View available Computer Science - Other 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.