<jupyter_start><jupyter_text>Lab 7<jupyter_code>library(DataComputing)
library(magrittr)
library(ggplot2)
library(dplyr)<jupyter_output><empty_output><jupyter_text>Question 1<jupyter_code># built-in dataset in R
head(airquality)<jupyter_output><empty_output><jupyter_text>Change data from wide to narrow format (above) using gather function. Group Ozone, Solar.R, Wind, Temp into one variable called `type` and create another column called `value` to store their values. Your output should look like this:  Question 2Suppose you have a data frame, `data`, as given below:<jupyter_code># Data frame for questions
data <- data.frame(V1 = rep(c("a","b","c"), each = 2),
                   V2 = rep(c(1:2), times = 3),
                   V3 = rep(c("alpha", "beta", "gamma")),
                   V4 = seq(10, 60, by = 10))
print(data)<jupyter_output><empty_output><jupyter_text>Assuming that the `tidyr` and `dplyr` libraries are already loaded, write down what the output for the following code.  The final result is enough for full credit, but partial credit will be given for writing out and labelling intermediate steps.<jupyter_code>data %>%
  filter(V1 == "a") %>% # Step 1
  select(V2, V4) %>% # Step 2
  gather(key = Apple, value = Banana, V2, V4) %>% # Step 3
  mutate(Apple = Banana) # Step 4<jupyter_output><empty_output><jupyter_text>Question 3Suppose you have a data frame, `data`, as given below.a) Write a function called `fix_missing_99` that takes one argument: `x`, a numeric vector.  The function should replace every component of `x` equal to -99 with `NA`.b) Write a loop that replaces every -99 in `data` with `NA`.  For full credit, your code must use the function in part (a) and it should continue to work without modification if additional columns are added to the data frame.c) Write down an appropriate call from the `apply` family of functionals to perform the same task as in part (b).<jupyter_code>set.seed(1014)
data <- data.frame(replicate(6, sample(c(1:10, -99), 6, rep = TRUE)))
names(data) <- letters[1:6]
data<jupyter_output><empty_output><jupyter_text>Question 4Assuming the 'ggplot2' is already loaded. The first 6 rows of the 'diamond' dataset are:<jupyter_code>head(diamonds)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11061552185548618, 'fraction_numerical': 0.02230151650312221, 'mean_word_length': 4.981333333333334, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '636524', 'license': 'MIT', 'n_tokens_mistral': 752, 'n_tokens_neox': 701, 'n_words': 261, 'path': 'lab7/midterm_review-1.ipynb', 'repo_name': 'young-geng/stat133', 'size': '2242'}