--- title: "Problem Set 0" author: "Your name here" output: html_document: df_print: paged --- ## Introduction to Markdown in RMarkdown (or Quarto) Quarto and RMarkdown are two avenues for creating analytic reports and documents. They allow you to mix together text and code, and allow the code's output to live within the document directly. They can be output to various formats, such as pdf and word. Move between source view and visual view to help understand how the document is actually structured. ## Running Code When you click the **Render** button a document will be generated that includes both content and the output of embedded code. You can embed code like this: ```{r} 1 + 1 ``` You can add options to executable code like this ```{r} #| echo: false 2 * 2 ``` This problem set is intended to be a very basic introduction to some of the functions of R. You should load this into R Studio, and should be able to run the entire file. For each of the problems, even if you can think of another way to do it, answer the question using R. For each of the following questions, provide R commands used to solve the problem, and example output. Include both the questions and answers in your solution. You can use this markdown file to turn in; you should include the relevant code you used in the markdown, but **EVERY QUESTION SHOULD BE ANSWERED IN WORDS**, along with the expressions and output supporting that response (usually as part of the markdown). Turn in a text file or word file with your answers to each question, including the R calculations and the final values. # 1. Calculating a mean The Walker Family has five sisters. In order of age, their heights are 1.52, 1.48, 1.45, 1.81, and 1.71 meters. Write an expression that calculates the average height of the five women, in meters. You should only need to use (, ), /, and + along with numbers to solve this. ```{r} ``` # 2. Converting dimensions. There are 3.281 feet per meter. Calculate the number of feet of the average height of the women. You should do this by taking the expression for part 1 and adding the necessary additional operations to do this conversion. ```{r} ``` # 3. Converting to feet and inches. +, -, \*, /, and \^ are all commonly-known math operators. Two lesser-known are mod and div, which in R are %% and %/%. Together, these tell you how many complete times a number goes into another number, and what number is left over. This is sort of like in long division, 23/7 is 3 remainder 2. We say that 23 mod 7 is 2 and 23 div 7 is 3. Mod and div by 1 gives us the numbers to the left and right of the decimal place. Using the 'mod-by-one' operator (%% 1) will tell us the 'remainder' part of a whole number decimal, while the 'div-by-one' operator (%/% 1) will tell us the whole number. To understand this, look at what the following produce: ```{r} print(12.3456 %% 1) ## mod-by-one print(12.3456 %/% 1) ## div-by-one ``` Use the div-by-1 operator to extract the foot portion of the average height of the Walker sisters calculated in part 2. Then use the mod-by-1 operator to extract the decimal portion of the average height in feet, and convert this to inches. Caution: mod and div have a higher order of precedence than multiplication--they take place first. Be sure to use proper parenthesis to get the right answer. What is the average height of the women in feet-and-inches? # 4. Normalizing Suppose we wanted to make a new measurement unit called 'The walker', where one walker is the average height of the Walker sisters. Calculate the height, in Walker-units, of the following celebrities and musicians: - Glen Powell - Chappel Roan - Alan Ritchson - Gracie Abrams - Sydney Sweeney - Noah Kahan Use a reputable source such as IMDB, https://www.celebheights.com/, or an LLM to obtain a barefoot height estimate in feet-and-inches (or just guess if you must), and then convert these to walker-units. Make sure these are saved in a vector using '''c()'''. Create another vector that lists the names. Create a third vector that lists the popularity of each celebrity based on the number of search engine hits, social media followers, mentions on twitter/x, ChatGPT prompt, or some other metric you decide on. Do all calculations via R, and show your work. ```{r} ##code goes here height.in.feet <- c(,,,,,) ##fill in numbers of the foot-height, as an integer. i.e., 5 foot 3.5 is a 5 height.in.inches <- c(,,,,,) ##fill in the inches, as a float. i.e., 5 foot 3.5 is 3.5 height.in.meters <- #### calculate this from feet and inches height.in.walkers <- #### calculate this here names <- c("","","","","","") popularity <- c(,,,,,) ``` # 4. Volleyball! If you were to host a celebrity coed 3-on-3 beach volleyball match, who would go on each team? What is the average walker index for each team? To do this, make vectors with T and F to select/filter each team and compute means. Which team is, on average, more popular according to your popularity metric? ***The team1 and team2 definitions below are just for example. These are not fair teams. Re-write team1/team2 lines so that the teams are as fair as possible.*** ```{r} ##code goes here ##example team 1 team1 <- c(T,T,T,F,F,F) team2 <- c(F,F,F,T,T,T) ##mean height of team 1: mean(height.in.walkers[team1]) ## Mean height of team 2: ## Mean popularity of Team1: ## Mean popularity of Team2: ``` # Height vs Popularity? Is there a relationship between height and popularity? Use plot() to plot the heights by the popularity. Label the x and y axes and the main title using the xlab, ylab, and main arguments. ```{r} plot() ```