-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Susan Vanderplas
committed
Dec 20, 2023
1 parent
3a8124f
commit 933df48
Showing
75 changed files
with
4,910 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"hash": "62b9e44ed9e08be0b9f9c9baa13b3445", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: Exam 1\nauthor: Your Name\ndate: '2024-03-07'\ncategories:\n- Week07\n- Exam\neditor: visual\npub-date: '2023-03-05'\n---\n\n\nYour goal on this exam is to demonstrate competency in as many of the [objectives](objectives.qmd) of chapters we've covered in this class so far as you can.\n\n## Ground Rules\n\n- You may use the textbook and the internet (but the same rules apply - you must be able to explain your answer!)\n\n- You may NOT confer with other people or AI entities - including posting on StackOverflow, Reddit, etc.\n\n- You may ask clarifying questions of Dr. Vanderplas by email/zoom or in person\n\n- You may use R or Python for any of these tasks, but your code must be reproducible - I must be able to run your quarto file on my machine. I have provided R chunks in the correct locations in this file - change them to Python if you wish.\n\n- For any plot or table you create, be sure to appropriately caption and label it, providing 1-2 sentences to highlight the main purpose/conclusions you can draw from that plot.\n\n- You should have at least one code chunk for each \\## heading below.\n\n# Pockets\n\nJean pockets are useful for carrying a multitude of different items around, but this utility is not evenly shared: women's pants often have pockets which are large enough to hold chapstick but not a pen, let alone a cell phone.\n\nThe Pudding assembled a dataset of jean pocket size measurements, which you can find [here](https://github.com/the-pudding/data/tree/master/pockets). There are two different data sets: the raw pocket measurements, and a second data file of measurements of the largest rectangle with could theoretically fit into the pocket of each pair of jeans evaluated.\n\n## Read in the Data\n\nWrite code which will:\n\n1. Download the raw pocket `measurements.csv` data to a file in this repository\n2. Read the data in, ensuring that columns containing numbers are appropriately formatted. You may consider the fabric column as a character string.\n\n\n::: {.cell}\n\n:::\n\n\n## Conduct an Exploratory Data Analysis\n\nGenerate at least 3 questions about the data set and find answers to those questions using charts, tables, or numerical summaries.\n\n### Questions\n\n1. \n\n2. \n\n3. \n\n### Question Answers\n\n\n::: {.cell caption='My caption'}\n\n:::\n\n\nYour discussion of this output goes here.\n\n\n::: {.cell caption='My caption'}\n\n:::\n\n\nYour discussion of this output goes here.\n\n\n::: {.cell caption='My caption'}\n\n:::\n\n\nYour discussion of this output goes here\n\n## Comparing Sexes and Styles\n\nGenerate one or two plots which best showcase the difference in pocket sizes for different sexes and styles of pants. Use The Pudding's classification for pants styles, treating straight and boot-cut styles as the same and skinny and slim styles as the same.\\\nYou may annotate the plot with the output from statistical tests if you wish, but it is sufficient to highlight the visual differences. Your chart(s) must have appropriate titles and axis labels, and must be constructed to take into account the principles of good graphics discussed in the textbook.\n\n\n::: {.cell caption='your caption here'}\n\n:::\n\n\nYour discussion of this output goes here.\n\nReplace this paragraph with 1-2 sentences discussing what choices you made to make the plot you generated above perceptually optimal. Which principles of good graphics did you use?\n\n# Cell Phone Dimensions\n\nDr. Vanderplas is interested in finding a pair of pants (from either the men's section or the women's section) which can accommodate her cell phone.\n\nHere is some code to read in the data in R and Python and extract the rectanglePhone dataset.\n\n\n::: {.cell}\n\n```{.r .cell-code}\njsonfile <- \"https://raw.githubusercontent.com/the-pudding/data/master/pockets/measurementRectangles.json\"\n\nlibrary(jsonlite)\nlibrary(tidyr)\nrects <- fromJSON(jsonfile)\nrectanglePhone <- rects %>% unnest(\"rectanglePhone\")\n```\n:::\n\n::: {.cell}\n\n```{.python .cell-code}\njsonfile = \"https://raw.githubusercontent.com/the-pudding/data/master/pockets/measurementRectangles.json\"\n\nimport pandas as pd\nrects = pd.read_json(jsonfile)\nrectanglePhoneDims = pd.DataFrame.from_records(rects['rectanglePhone'], nrows = 80)\nrectanglePhone = pd.concat([rects.iloc[:,0:21].reset_index(drop=True), rectanglePhoneDims], axis = 1)\n```\n:::\n\n\nWrite a function `checkpants(phonelength, phonewidth)` which takes length and width in centimeters and uses the largest rectangle data set from The Pudding to identify pants compatible with a specific cell phone's length and width. Return the following information in a list:\n\n- `front` - A data frame all jeans which can fit a rectangle of the specified dimension in the front pocket\n\n- `back` - a data frame of all jeans which can fit a rectangle of the specified dimension in the back pocket. Assume a phone fits in the back pocket if the width is less than the `minWidthBack` measurement and the `minHeightBack` measurement is at least 70% of the phone's height.\n\n- `price` - The average price of a pair of jeans which can fit the specified dimension in either the front or back pocket\n\n- `propMenFront` - the proportion of men's pants that can fit a rectangle of the specified dimension in the front pocket\n\n- `propWomenAny` - the proportion of women's pants that can fit a rectangle of the specified dimension in any pocket\n\nYou should ensure that you carefully read [the dataset documentation](https://github.com/the-pudding/data/tree/master/pockets) to understand the data you are using before you attempt this question.\n\n\n::: {.cell}\n\n:::\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
_freeze/homework-repos/02-review-r-python/index/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"hash": "1fc8a28a4cfd99382374d8deb67e542e", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: \"Homework 2: Reviewing R and Python\"\nauthor: \"Your Name\"\ndate: \"Due: Feb 5, 2023\"\noutput: html_document\n---\n\n\n\n\nA palindrome is a string that is equal to the reverse of that string, such as \"Mom\", \"Hannah\" or \"We panic in a pew.\"\n\nTraditionally, a phrase is tested for being a palindrome once all spaces and punctuation has been removed, and all letters are written in the same case. You will need to think about how to do these tasks in R and python.\n\n# Problem 1: Simple Palindromes\n## Pseudocode\n\nWrite a detailed list of steps to process a string named `test` to test that it is a palindrome. \n\nYou may find it helpful to write down some test words and work through them as if you were an algorithm. If you do this, please take a picture of your scratch paper, put it in the homework directory, and add it to your git repository along with your assignment solution.\n\nHint: The final items in this list of steps should be defining a variable `revtest` that is `test` with the letters reversed, and then comparing `test` and `revtest` for equality.\n\n\n\n## R\n\nTurn your pseudocode into a sequence of statements in R that work with a variable named `test`.\nAt this point, there is no need to write these steps in a function - we'll get there.\n\n\n::: {.cell hash='index_cache/html/unnamed-chunk-1_aafd36b202da46e11c983f8bd30f521d'}\n\n```{.r .cell-code}\ntest <- \"Hannah\"\ntest2 <- \"not-a-palindrome\"\n\n# Your steps go here\n```\n:::\n\n\n\n## Python\n\nTurn your pseudocode into a sequence of statements in python that work with a variable named `test`.\nAt this point, there is no need to write these steps in a function - we'll get there.\n\n\n::: {.cell hash='index_cache/html/unnamed-chunk-2_744089bdf43c411746b292b20f45d471'}\n\n```{.python .cell-code}\ntest = \"Hannah\"\ntest2 = \"not-a-palindrome\"\n\n# Your steps go here\n```\n:::\n\n\n\n# Problem 2: Functional Palindromes\n\nIn R and Python, use your code above to create a function, `palindrome`, which takes an argument, `x`, and returns a logical value indicating whether `x` is a palindrome.\n\n\n::: {.cell hash='index_cache/html/unnamed-chunk-3_23d6d8daf5f5f2d886ce10f78a3fe1e9'}\n\n```{.r .cell-code}\n# Your R function goes here\n```\n:::\n\n::: {.cell hash='index_cache/html/unnamed-chunk-4_664c35c0795d58e992c7d905949d1f29'}\n\n```{.python .cell-code}\n# Your python function goes here\n```\n:::\n\n\n\n# Problem 3: Vectors of Palindromes\n\nUse a loop, map, or apply statement to find all of the palindromes in a vector. I should be able to provide a different vector and use your function to find all of the palindromes.\n\n\n::: {.cell hash='index_cache/html/unnamed-chunk-5_be88d88af82fbd35ff224ca5f91d2718'}\n\n```{.r .cell-code}\ntest_vec <- c(\"taco cat\", \"UFO tofu\", \"In palindromes, spacing, punctuation, and capitalization are usually ignored.\", \"Borrow or rob?\", \"dithyrambic\", \"Never odd or even.\", \"R rules, Python drools!\", \"Won't lovers revolt now?\", \"Ma is a nun, as I am.\")\n```\n:::\n\n::: {.cell hash='index_cache/html/unnamed-chunk-6_8b4caa3e3a752bbfe53e8399eaac1ef9'}\n\n```{.python .cell-code}\ntest_vec = [\"taco cat\", \"UFO tofu\", \"In palindromes, spacing, punctuation, and capitalization are usually ignored.\", \"Borrow or rob?\", \"dithyrambic\", \"Never odd or even.\", \"R rules, Python drools!\", \"Won't lovers revolt now?\", \"Ma is a nun, as I am.\"]\n```\n:::\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"hash": "95e908607d6646f57a446a9b718f7c2d", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: 'Homework 2: Review'\ndate: '2024-02-05'\nauthor: Homework\ncategories:\n- Week02\n- HW\n---\n\n\nNote: This assignment must be submitted in github classroom.\n\n---\ntitle: \"Homework 2: Reviewing R and Python\"\nauthor: \"Your Name\"\ndate: \"Due: Feb 3, 2023\"\noutput: html_document\n---\n\n\n\nA palindrome is a string that is equal to the reverse of that string, such as \"Mom\", \"Hannah\" or \"We panic in a pew.\"\n\nTraditionally, a phrase is considered a palindrome once all spaces and punctuation has been removed, and all letters are written in the same case.\n\n# Problem 1: Simple Palindromes\n## Pseudocode\n\nWrite a detailed list of steps to process a string named `test` to test that it is a palindrome. \n\nHint: The final items in this list of steps should be defining a variable `revtest` that is `test` with the letters reversed, and then comparing `test` and `revtest` for equality.\n\n\n\n## R\n\nTurn your pseudocode into a sequence of statements in R that work with a variable named `test`.\nAt this point, there is no need to write these steps in a function - we'll get there.\n\n::: {.cell hash='02-review_cache/html/unnamed-chunk-1_ed9dc7184c74209034bcab0240b8d1ce'}\n\n```{.r .cell-code}\ntest <- \"Hannah\"\n\n# Your steps go here\n```\n:::\n\n\n## Python\n\nTurn your pseudocode into a sequence of statements in python that work with a variable named `test`.\nAt this point, there is no need to write these steps in a function - we'll get there.\n\n::: {.cell hash='02-review_cache/html/unnamed-chunk-2_d811425565d192dbafebb99fa5405b0b'}\n\n```{.python .cell-code}\ntest = \"Hannah\"\n\n# Your steps go here\n```\n:::\n\n\n# Problem 2: Functional Palindromes\n\nIn R and Python, use your code above to create a function, `palindrome`, which takes an argument, `x`, and returns a logical value indicating whether `x` is a palindrome.\n\n::: {.cell hash='02-review_cache/html/unnamed-chunk-3_9a0c817840c79f498ce87ed3fca1ffce'}\n\n```{.r .cell-code}\n# Your R function goes here\n```\n:::\n\n::: {.cell hash='02-review_cache/html/unnamed-chunk-4_38955cf7e408f8282510381f4fa89437'}\n\n```{.python .cell-code}\n# Your python function goes here\n```\n:::\n\n\n# Problem 3: Vectors of Palindromes\n\nUse a loop, map, or apply statement to find all of the palindromes in a vector. I should be able to provide a different vector and use your function to find all of the palindromes.\n\n::: {.cell hash='02-review_cache/html/unnamed-chunk-5_6b678105d97be3a53981adb741edaa0a'}\n\n```{.r .cell-code}\ntest_vec <- c(\"taco cat\", \"UFO tofu\", \"In palindromes, spacing, punctuation, and capitalization are usually ignored.\", \"Borrow or rob?\", \"dithyrambic\", \"Never odd or even.\", \"R rules, Python drools!\", \"Won't lovers revolt now?\", \"Ma is a nun, as I am.\")\n```\n:::\n\n\n::: {.cell hash='02-review_cache/html/unnamed-chunk-6_31a8bebbaeaf695b21b0f57bef782739'}\n\n```{.python .cell-code}\ntest_vec = [\"taco cat\", \"UFO tofu\", \"In palindromes, spacing, punctuation, and capitalization are usually ignored.\", \"Borrow or rob?\", \"dithyrambic\", \"Never odd or even.\", \"R rules, Python drools!\", \"Won't lovers revolt now?\", \"Ma is a nun, as I am.\"]\n```\n:::\n\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"hash": "7a5c29ba290f58038211b9e2302cf4e3", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: 'Homework 3: Cipher'\ndate: '2024-02-12'\nexecute-dir: ../homework-repos/03-cipher\nengine: knitr\nauthor: Homework\nexecute:\n error: true\n eval: false\ncategories:\n- Week03\n- HW\n---\n\n\nNote: This assignment must be submitted in github classroom.\n\n\n\n---\ntitle: \"decodeR: Base R\"\nexecute:\n error: true\noutput: html_document\n---\n\nThis assignment is modified from the [decodeR](https://github.com/kbodwin/decodeR) exercises by Kelly Bodwin and Allison Theobold.\n\n\nIn this assignment, you will be creating and manipulating vectors, lists, and data frames to uncover a top secret message.\n\nSome advice:\n\n* Work with those around you\n* Google is your friend! If an error is confusing, copy it into Google and see what other people are saying. If you don't know how to do something, search for it.\n* Just because there is no error message doesn't mean everything went smoothly. Use the console to check each step and make sure you have accomplished what you wanted to accomplish.\n\n\n\n## Part One: Setup\n\nEach of the following R chunks will cause an error and/or do the desired task incorrectly. Find the mistake, and correct it to complete the intended action. For each error, write 1-2 sentences to reflect on what the mistake was and how you found it and fixed it.\n\n1. Create vectors containing the upper case letters, lower case letters, and some punctuation marks.\n\n::: {.cell hash='03-cipher_cache/html/unnamed-chunk-2_aa6114b18bbd12fbdde7b1842ac8f4f7'}\n\n```{.r .cell-code}\nlower_case <- c(\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \"y\", \"z\")\n\nupper_case <- c(\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\" \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\")\n\npunctuation <- c(\".\", \",\", \"!\", \"?\", \"'\", \"\"\", \"(\", \")\", \" \", \"-\", \";\", \":\")\n```\n:::\n\n2. Make one long vector containing all the symbols.\n\n::: {.cell hash='03-cipher_cache/html/unnamed-chunk-3_3b12fe5c094c511e39f59db4075e2bd5'}\n\n```{.r .cell-code}\nmy_symbols <- cbind(lower_case, upper_case, punctuation)\n```\n:::\n\n3. Turn the `my_symbols` vector into a data frame, with the variable name \"Symbol\"\n\n::: {.cell hash='03-cipher_cache/html/unnamed-chunk-4_65a82ad6d4881081dd052a2b520cfa40'}\n\n```{.r .cell-code}\nmy_symbols <- dataframe(my_symbols)\nnames(my_symbols) = Symbol\n```\n:::\n\n\n4. Find the total number of symbols we have in our data frame. \n\n::: {.cell hash='03-cipher_cache/html/unnamed-chunk-5_8386cf390a99fe5136fd2e078b7813c1'}\n\n```{.r .cell-code}\nlen <- length(my_symbols)\n```\n:::\n\n\n5. Create a new variable in your dataframe that assigns a number to each symbol.\n\n::: {.cell hash='03-cipher_cache/html/unnamed-chunk-6_ed16df7a9960a422e029a84fc70193e8'}\n\n```{.r .cell-code}\nmy_symbols%Num <- 1:len\n```\n:::\n\n\n\n## Part Two: Decoding the secret message.\n\nThis chunk will load up the encoded secret message as a vector:\n\n::: {.cell hash='03-cipher_cache/html/unnamed-chunk-7_3f268d91f7f305952a065103030e9aaf'}\n\n```{.r .cell-code}\ntop_secret <- read.csv(\"Secret_Code\", header = FALSE)$V1\n```\n:::\n\nBy altering this top secret set of numbers, you will be able to create a message. Write your own code to complete the steps below.\n\n1. Add 14 to every number.\n2. Multiply every number by 18, then subtract 257.\n3. Exponentiate every number. (That is, do e\\^[number].)\n4. Square every number.\n\n**Checkpoint:** Headquarters has informed you that at this stage of decoding, there should be 352 numbers in the secret message that are below 17.\n\n5. Turn your vector of numbers into a matrix with 5 columns.\n6. Separately from your top secret numbers, create a vector of all the even numbers between 1 and 382. Name it \"evens\". That is, \"evens\" should contain 2, 4, 6, 8 ..., 382.\n7. Subtract the \"evens\" vector from the first column of your secret message matrix.\n8. Subtract 100 from all numbers in the 18-24th rows of the 3rd column.\n9. Multiply all numbers in the 4th and 5th column by 2.\n10. Turn your matrix back into a vector.\n\n**Checkpoint:** Headquarters has informed you that at this stage of decoding, all numbers in indices 500 and beyond are below 100.\n\n\n11. Take the square root of all numbers in indices 38 to 465.\n12. Round all numbers to the nearest whole number.\n13. Replace all instances of the number 39 with 20.\n\n**Checkpoint:** Headquarters has informed you that your final message should have 344 even numbers.\n\n\n## Part 3: The secret message!\n\nUse your final vector of numbers as indices for `my_symbols` to discover the final message! \nGoogle the first line of this message, if you do not recognize it, to see what it is.\n\n\nWrite 3-4 sentences about what you learned from this investigation. What problems did you encounter, and how did you solve them? Could you do the same tasks in Python? Why or why not?\n\n\n\n\n", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
Oops, something went wrong.