ps3_YashPatel

pdf

School

Pennsylvania State University *

*We aren’t endorsed by this school

Course

184

Subject

Mathematics

Date

Feb 20, 2024

Type

pdf

Pages

2

Uploaded by MagistrateOwl2160

Report
Problem Set 3 Yash Patel 02/07/2024 7.1 For each of the operations listed here, say whether it involves a transformation function or a reduction function or neither. part i) Determine the 3rd largest. Ans: Reduction Function part ii) Determine the 3rd and 4th largest values. Ans: Reduction Function part iii) Determine the number of cases. Ans: Neither part vi) Determine whether a year is a leap year. Ans:Neither part v) Determine whether a date is a legal holiday. Ans:Neither part vi) Determine the range of a set, that is, the max minus the min. Ans: Transformation Function part vii) Determine which day of the week (e.g., Sun, Mon, . . . ) a given date is. Ans: Neither part viii) Find the time interval in days spanned by a set of dates. Ans: Transformation Function 7.4 Each of these statements has an error. It might be an error in syntax or an error in the way the data tables are used, etc. Write down a correct version of the statement. part i) Ans:BabyNames %>% group_by(year, sex) %>% summarise(total = sum(count)) part ii) Ans: ZipGeography %>% group_by(State) %>% summarise(pop = sum(Population)) part iii) Ans:Minneapolis2013 %>% group_by(First) %>% summarise(voteReceived = n()) part iv) Ans:Minneapolis2013 %>% group_by(First) %>% summarise(votesReceived = n()) 1
7.5 The data verbs group_by() and summarise() are very frequently used in combination. Experiment with the R code, help documentation, etc to investigate each of the following. part i) Ans: Groups the data by First and Second variables.Each row represents a unique combination of First and Second values. part ii) Ans: Calculates the total number of rows (cases) in the entire dataset. Each row represents the entire dataset. part iii) Ans: Intended to group by First and Second and then calculate the count within each group, but throws an error. Intended case representation similar to VoterData_A. part iv) Ans:Throws an error because grouping by First and Second happens after summarizing the entire dataset.summarise() essentially reduces the data to a single row with the specified summary (total count in this case). Then, trying to group this single row by variables that no longer exist in the data leads to the error. 7.7 You have a statement in the form Patients %>% group_by(SOME_VARIABLES ) %>% summarise(count = n(), meanAge= mean(age)) part i) Sex Ans: variables that will appear.sex,count,meanAge part ii) diagnosis Ans:variables that will appear:diagnosis, count, meanAge part iii) sex, diagnosis Ans: variables that will appearsex,diagnosis, count,meanAge part iv) age, diagnosis Ans:variables that will appear:age,diagnosis, count, meanAge part v) age Ans:variables that will appear:age,count,meanAge # This template file is based off of a template created by Alex Hayes # https://github.com/alexpghayes/rmarkdown_homework_template # Setting Document Options knitr :: opts_chunk $ set ( echo = TRUE , warning = FALSE , message = FALSE , fig.align = "center" ) 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help