Skip to content

Commit 46a63f9

Browse files
committed
deploy: 22627f2
1 parent 3092880 commit 46a63f9

File tree

1,993 files changed

+1011224
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,993 files changed

+1011224
-10
lines changed

.Rprofile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
source("renv/activate.R")

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata
5+
6+
*.DS_Store
7+
8+
/.quarto/

README.md

Lines changed: 20 additions & 0 deletions

Rclass-DataScience.Rproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX

_freeze/class0/execute-results/html.json

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.

_freeze/class1/execute-results/html.json

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hash": "def8a53c9a471a9d8fc48c57c63225de",
3+
"result": {
4+
"engine": "knitr",
5+
"markdown": "---\ntitle: \"Applying Coding Basics\"\nsubtitle: \"Coding Basics, Day 2\"\nauthor: \"Matthew Sutcliffe, Madeline Gillman, JP Flores\"\nformat: \n html: \n toc: true\n---\n\n\n\n\n## Objectives of Coding Basics: Class 2\n\n- Be able to apply the objectives covered in Coding Basics: Class 1 to a new dataset\n\n- Identify and fix a bug in a code example\n\n## Your datasets\n\nThis class we will be working with the `mtcars` dataset. The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973--74 models).\n\nThe other dataset we will be working with is the Palmer Penguins dataset. This is not a built-in dataset, so you will need to install it. You will only need to install the package once.\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# this code is making sure that the correct files are installed during the project rendering\n# Students, don't worry too much about this code. It is here to make sure that our curriculum\n# book runs correcrtly, but if you are curious, feel free to ask teachers for more info. \nif(!require(\"palmerpenguins\")){\n install.packages(\"palmerpenguins\",repos = 'http://cran.us.r-project.org')\n}\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\ninstall.packages(\"palmerpenguins\")\n```\n:::\n\n\n\n\nOnce it is installed, you will need to load the package into your R environment. You will need to do this anytime you want to use a package.\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(palmerpenguins)\n```\n:::\n\n\n\n\nYou will also need to load the penguins dataset into your R environment:\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ndata(package = \"palmerpenguins\")\n```\n:::\n\n\n\n\n## Today's class\n\n### Cars dataset\n\n1. The dataset is stored 'under the hood' in an object called `mtcars`. View the dataset. Use `head()` to view the first 5, 10, and 20 rows.\n2. Assign `mtcars` to a new variable of your choice.\n3. What is the data type of each column in the dataset?\n4. How many rows are in the dataset? How many columns? You may need to look up how to do this! Try searching \"how to get number of rows in data frame in R\" in Google.\n5. Run `str(mtcars)` . What is this output telling you? How does it compare to what you found in #3 and #4?\n6. For each column, find the mean, range, and median values. Are you able to do this for all columns? Why or why not?\n7. What value is in the 6th row and 10th column?\n8. Print every row of the 4th column.\n9. Print every column of only rows 28 to 31.\n\n### Penguins dataset\n\n1. The dataset is stored 'under the hood' in an object called `penguins`. View the dataset. Use `head()` to view the first 5, 10, and 20 rows.\n2. Assign `penguins` to a new variable of your choice.\n3. What is the data type of each column in the dataset?\n4. How many rows and columns?\n5. For each column, if possible, find the mean, range, and median values.\n6. For columns that you cannot find the mean/range/median of, try using the `table()` function, e.g. `table(penguis$species)` . What is this telling you?\n7. Currently, the `bill_length` and `bill_depth` columns are in millimeters. Create a new column with those values converted to centimeters. (HINT: look at what you did at the end of the \"Accessing parts of a list\" section in Class 1)\n8. Add two new columns to the data frame of your choice.\n9. The penguins dataset is not perfect--it has some missing values. Check the missing values in the column sex by running two functions: `is.na(penguins$sex)` and `sum(is.na(penguins$sex))` .\n a. What is the difference between the two outputs?\n b. Compare to the result in #6.\n c. Use the help page for the `table()` function and see if you can get the output to include NAs.\n\n### Code debugging\n\nYour former lab mate Weird Barbie graduated a few years ago. Before she left, she was working on some interesting analyses of the frequencies of Kens.\n\nThis is a test\n\n![photo credit: Warner Bros.](data/class2_files/weirdbarbie.jpeg){fig-align=\"center\"}\n\nHere's the data below, which you will not (and should not) need to change:\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# The data -- DO NOT EDIT \nken_data <- data.frame(\n \"ken_name\" = c(\"Ken1\", \"Ken2\", \"Ken3\", \"Ken4\", \"Ken5\", \"Ken6\", \"Ken7\", \"Allan\"),\n \"hair_color\" = c(\"Blonde\", \"Brown\", \"Black\", \"Red\", \"Blonde\", \"Brown\", \"Black\", \"Black\"),\n \"cowboy_hats_owned\" = c(2, 0, 1, 3, 0, 1, 2, 0),\n \"favorite_outfit\" = c(\"Casual\", \"Formal\", \"Sporty\", \"Beachwear\", \"Formal\", \"Casual\", \"Sporty\", \"Casual\"),\n \"age\" = c(25, 27, 26, 28, 29, 30, 26, 27),\n \"height_cm\" = c(180, 175, 182, 178, 180, 183, 177, 175),\n \"weight_kg\" = c(75, 70, 80, 77, 76, 78, 79, 70),\n \"favorite_hobby\" = c(\"Surfing\", \"Reading\", \"Soccer\", \"Volleyball\", \"Painting\", \"Cooking\", \"Dancing\", \"Guitar\"),\n \"favorite_color\" = c(\"Blue\", \"Green\", \"Red\", \"Yellow\", \"Purple\", \"Orange\", \"Pink\", \"Blue\"),\n \"shoe_size\" = c(10, 9, 11, 10, NA, 11, 10, 9),\n \"best_friend\" = c(\"Barbie\", \"Barbie\", \"Barbie\", \"Barbie\", \"Barbie\", \"Barbie\", \"Barbie\", NA),\n \"is_ken\" = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE)\n)\n```\n:::\n\n\n\n\nHowever, as is typical of Weird Barbie, her code is...weird. In almost all other aspects of life, that's OK! But when it comes to you, three years later, trying to figure out what she did...not ideal. Here's her code below. As it's written, there are many bugs (code errors that either return an error or return an unexpected/incorrect result), the style is inconsistent, and there is no documentation. Using what you have learned so far, fix Weird Barbie's code: find the bugs, smash the bugs (get the code to run), change to a consistent style, and add helpful comments. You may need to consult the style guide mentioned in Class 0, help pages, and Google.\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nstr(ken_data)\nhaed(ken_data)\n\nmean(ken_data$cowboy_hats_owned)\nhist(ken_data$cowboy_hats_owned)\nken_data$more.than.1_cowboyHat <- ken_data$cowboy_hats_owned > 1\nprint(paste(sum(ken_data$more.than.1_cowboyHat), \"Kens have more than 1 cowboy hat\"))\n\nrange(ken$age)\nrange(ken_data$shoe_size)\n\n\ncorrelation <- cor(ken_data$height_cm, ken_data$weight_kg)\nprint(paste(\"The correlation between height and weight is\", correlation))\nplot(ken_data$height_cm, ken_data$weight_kg)\n\ntable(ken_data$best_friend)\n# looks like everyone's bff is barbie!\n\n# outfits\ntable(ken_data$favorte_outfit)\n\n\n# no allan\nrange(ken_data[1:7,5])\n\nnoAllan <- ken_data[1:7,]\nalso_noAllan <- noAllan <- ken_data[ken_data$is_ken == TRUE,]\nrange(noAllan$shoe_size)\n\n# Are the sporty Kens taller than the other Kens?\nsporty_kens <- mean( ken_data [ken_data$favorite_outfit == \"Sporty\", \"height_cm\"])\nother_kens_mean <- mean(ken_data[ken_data$favorite_outfit != \"Sporty\", \"height_cm\"] )\n\nsporty_kens > other_kens_mean\n```\n:::",
6+
"supporting": [],
7+
"filters": [
8+
"rmarkdown/pagebreak.lua"
9+
],
10+
"includes": {},
11+
"engineDependencies": {},
12+
"preserve": {},
13+
"postProcess": true
14+
}
15+
}

_freeze/class3/execute-results/html.json

Lines changed: 15 additions & 0 deletions
Large diffs are not rendered by default.
22.3 KB
24.9 KB

0 commit comments

Comments
 (0)