Overview

This file contains a set of tasks that you need to complete in R for the lab assignment. The tasks may require you to add a code chuck, type code into a chunk, and/or execute code. Some tasks may also ask you to answer specific questions. Don’t forget that you need to acknowledge if you used any resources beyond class materials or got help to complete the assignment.

More information and examples that can help you with this assignment can be found in the file “GettingtoKnowYourDataTutorial.html”.

The data set you will use is different than the one used in the instructions. Pay attention to the differences in the Excel file name and any variable names. You will need to adjust your code accordingly.

Once you have completed the assignment, you will need to publish it to produce an html file. You will then need to upload the html file and this .Rmd file to AsULearn.

1. Add your name and the date

The first thing you need to do in this file is to add your name and date in the lines underneath this document’s title (see the code in lines 10 and 11). While you will change the things in lines 10 and 11, you should not add anything new in this file until after line 42. Do not delete anything in the file.

2. Getting started

You need to identify and set your working directory, load packages, and load your data in this section. In addition to the openxlsx package that we used in the Getting Started in R lab, you also need to load the packages dplyr and tidyverse. Remember that before you load a package for the 1st time, you need to install the package. The name of the Excel file is different than what is in the instructions, you will need to adjust the code to read in the Excel file that was downloaded as part of the zip file.

Insert your chunks of code here to identify and set your working directory, load packages, and load the data. I recommend doing one thing per chunk of code.

getwd()
## [1] "/Users/Saniya Boger/Research Methods Lab/GettingToKnowYourDataFall2025"
setwd("/Users/Saniya Boger/Research Methods Lab/GettingToKnowYourDataFall2025")
install.packages("dplyr")
## 
## The downloaded binary packages are in
##  /var/folders/32/zb9p7dwj18l3xms644qqhmv80000gs/T//Rtmpl3tz11/downloaded_packages
install.packages("openxlsx")
## 
## The downloaded binary packages are in
##  /var/folders/32/zb9p7dwj18l3xms644qqhmv80000gs/T//Rtmpl3tz11/downloaded_packages
install.packages("tidyverse")
## 
## The downloaded binary packages are in
##  /var/folders/32/zb9p7dwj18l3xms644qqhmv80000gs/T//Rtmpl3tz11/downloaded_packages
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(openxlsx)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.5.2     ✔ stringr   1.5.1
## ✔ lubridate 1.9.4     ✔ tibble    3.3.0
## ✔ purrr     1.1.0     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# install.packages("devtools")
devtools::install_github("r-lib/conflicted")
## Skipping install of 'conflicted' from a github remote, the SHA1 (4d759ac6) has not changed since last install.
##   Use `force = TRUE` to force installation
remotes::install_github("r-lib/conflicted", force = TRUE)
## Downloading GitHub repo r-lib/conflicted@HEAD
## 
## ── R CMD build ─────────────────────────────────────────────────────────────────
##      checking for file ‘/private/var/folders/32/zb9p7dwj18l3xms644qqhmv80000gs/T/Rtmpl3tz11/remotes127955a1235fa/r-lib-conflicted-4d759ac/DESCRIPTION’ ...  ✔  checking for file ‘/private/var/folders/32/zb9p7dwj18l3xms644qqhmv80000gs/T/Rtmpl3tz11/remotes127955a1235fa/r-lib-conflicted-4d759ac/DESCRIPTION’
##   ─  preparing ‘conflicted’:
##    checking DESCRIPTION meta-information ...  ✔  checking DESCRIPTION meta-information
##   ─  checking for LF line-endings in source and make files and shell scripts
##   ─  checking for empty or unneeded directories
##   ─  building ‘conflicted_1.2.0.9000.tar.gz’
##      
## 
BBQData <- read.xlsx("BBQ_Assignment.xlsx")

If you are working in the cloud version of RStudio, you do not need to set the working directory because you will have had to load this file and the Excel file into the cloud to be able to access them. Instead right before your chunk of code write in all capital letters that you are using RStuiod in the cloud.

3. Take a look at your data

Display the first 15 observations of your data set.

view(BBQData)
head(BBQData, 10)
##       Sex Age              Hometown FavoriteMeat                  FavoriteSauce
## 1    Male  19 Eastern or Central NC beef brisket    Western style (with tomato)
## 2  Female  24 Eastern or Central NC  pulled pork Eastern style (with no tomato)
## 3  Female   2 Eastern or Central NC  pulled pork Eastern style (with no tomato)
## 4    Male  50             Elsewhere  pulled pork    Western style (with tomato)
## 5  Female  19 Eastern or Central NC    pork ribs         South Carolina Mustard
## 6  Female  20 Eastern or Central NC  pulled pork   Kansas style (with molasses)
## 7   Other  19 Eastern or Central NC  pulled pork Eastern style (with no tomato)
## 8    Male  23             Elsewhere beef brisket   Kansas style (with molasses)
## 9  Female  25 Eastern or Central NC  pulled pork    Western style (with tomato)
## 10 Female  49             Elsewhere  pulled pork Eastern style (with no tomato)
##    Sweetness FavoriteSide RestaurantCity    RestaurantName MinutesDriving
## 1          4        fries     Wilmington         Jackson's             20
## 2          1        other     Wilmington     Jackson's BBQ             20
## 3          4 hush puppies        Angier   Stephenson’s BBQ             20
## 4          3   fried okra     Wilson, NC           Parkers             30
## 5          3  baked beans           <NA>              <NA>              0
## 6          4     coleslaw           <NA>       Smithfields             15
## 7          3 hush puppies            n/a               n/a             20
## 8          3 hush puppies       Waco, TX              <NA>            240
## 9          3 hush puppies Smithfield, NC        Smithfield             30
## 10         2   fried okra Wilmington, NC Jackson’s Big Oak             45
##    SandwichPrice DinnerPlatePrice RibsPrice
## 1             13               11        15
## 2             10               15        20
## 3             10               16        20
## 4             15               20        35
## 5              5                7         9
## 6              3               18        20
## 7              6                8        10
## 8             15               20        25
## 9             20               25        30
## 10            15               90        35
tail(BBQData, 5)
##       Sex Age  Hometown FavoriteMeat                  FavoriteSauce Sweetness
## 11 Female  25 Elsewhere beef brisket                          Other         3
## 12 Female  18 Elsewhere  pulled pork                   Korean Style         4
## 13   Male 180 Elsewhere    pork ribs Eastern style (with no tomato)         3
## 14 Female  24 Elsewhere    pork ribs                   Korean Style         3
## 15   Male  22 Piedmount  pulled pork Eastern style (with no tomato)         3
##    FavoriteSide  RestaurantCity      RestaurantName MinutesDriving
## 11 hush puppies             N/A                 N/A             10
## 12        fries       Charlotte Midwood Smokehouse              60
## 13        other       Asheville         Daddy Mac’s             30
## 14        fries            cary           red robin             20
## 15 hush puppies Mooresville, NC     Lancaster's BBQ             30
##    SandwichPrice DinnerPlatePrice RibsPrice
## 11           120               20        30
## 12            15               20        35
## 13            15               17       200
## 14            10               15        15
## 15            11               15        20
names(BBQData)
##  [1] "Sex"              "Age"              "Hometown"         "FavoriteMeat"    
##  [5] "FavoriteSauce"    "Sweetness"        "FavoriteSide"     "RestaurantCity"  
##  [9] "RestaurantName"   "MinutesDriving"   "SandwichPrice"    "DinnerPlatePrice"
## [13] "RibsPrice"

Insert your chunk of code here to display your first 15 observations.

4. Create a unique id

Add a variable that is a unique id for each observation. Then take another look at the data. After creating the unique id variable, display the first 15 observations in your data set.

"BBQData %>%"
## [1] "BBQData %>%"
  "rowid_to_column(var = CaseID)->BBQData"
## [1] "rowid_to_column(var = CaseID)->BBQData"
head(BBQData, 5)
##      Sex Age              Hometown FavoriteMeat                  FavoriteSauce
## 1   Male  19 Eastern or Central NC beef brisket    Western style (with tomato)
## 2 Female  24 Eastern or Central NC  pulled pork Eastern style (with no tomato)
## 3 Female   2 Eastern or Central NC  pulled pork Eastern style (with no tomato)
## 4   Male  50             Elsewhere  pulled pork    Western style (with tomato)
## 5 Female  19 Eastern or Central NC    pork ribs         South Carolina Mustard
##   Sweetness FavoriteSide RestaurantCity   RestaurantName MinutesDriving
## 1         4        fries     Wilmington        Jackson's             20
## 2         1        other     Wilmington    Jackson's BBQ             20
## 3         4 hush puppies        Angier  Stephenson’s BBQ             20
## 4         3   fried okra     Wilson, NC          Parkers             30
## 5         3  baked beans           <NA>             <NA>              0
##   SandwichPrice DinnerPlatePrice RibsPrice
## 1            13               11        15
## 2            10               15        20
## 3            10               16        20
## 4            15               20        35
## 5             5                7         9

Insert your chunk of code here to create your unique id and then display your data.

5. Recode and clean numerical variables

In this section you need to covert variables into the numerical format and clean up any messy observations. The numerical variables you need address in this section are: Age, MinutesDirving, SandwichPrice, DinnerPlatePrice, and RibsPrice.

"BBQData$Age2 <- as.numeric(BBQData$Age)"
## [1] "BBQData$Age2 <- as.numeric(BBQData$Age)"
"BBQData$Age2[BBQData$Age2<17]<-NA"
## [1] "BBQData$Age2[BBQData$Age2<17]<-NA"
"print(BBQData$Age)"
## [1] "print(BBQData$Age)"
"print(BBQData$Age2)"
## [1] "print(BBQData$Age2)"

You know the following things about your data that will be helpful when conducting your recodes. First, all the respondents should be between the ages of 18 and 90. Second, no respondent is willing to drive more than 100 miles for BBQ. Third, it is unreasonable that the price of a sandwich is less than $5, the price of a dinner plate less than $15, or the price of ribs is less than $20. Fourth, no one should be willing to pay more than $50 dollars for a sandwich, dinner, or ribs.

After you have reformatted the variables and done the necessary recodes, use the print command to compare the original variables to your new variables.

Remember > means greater than and < means less than.

Insert your code here for recoding and cleaning numerical variables. I recommend doing one thing per chunk of code.

6. Recode and clean categorical variables

In this section you need to recode categorical variables to assign values to their different categories. The following are the categorical variables in the data set: Sex, FavoriteMeat, FavoriteSauce, FavoriteSide.

"BBQData %>%"
## [1] "BBQData %>%"
  "mutate(gender2 = NA)  %>%"
## [1] "mutate(gender2 = NA)  %>%"
  "mutate(gender2 = replace(gender2, BBQData$Sex == Male, 1))%>%"
## [1] "mutate(gender2 = replace(gender2, BBQData$Sex == Male, 1))%>%"
  "mutate(gender2 = replace(gender2, BBQData$Sex == Female, 2))%>%"
## [1] "mutate(gender2 = replace(gender2, BBQData$Sex == Female, 2))%>%"
  "mutate(gender2 = replace(gender2, BBQData$Sex == Other, 3)) -> BBQData"
## [1] "mutate(gender2 = replace(gender2, BBQData$Sex == Other, 3)) -> BBQData"
print(BBQData$Sex)
##  [1] "Male"   "Female" "Female" "Male"   "Female" "Female" "Other"  "Male"  
##  [9] "Female" "Female" "Female" "Female" "Male"   "Female" "Male"
print(BBQData$gender2)
## NULL

You should reference the code book for the BBQ data set to know the numerical values to assign to the different categories.

After you have completed recoding the variables, use the print command to compare the original variables to your new variables. Don’t forget capitalization matters.

Insert your code here for recoding and cleaning categorical variables. I recommend doing one thing per chunk of code.

Did you receive help?

Enter the names of anyone one that assisted you with completing this lab. If no one helped you complete just type type out no one helped you. Dr. Hicks # Did you provide anyone help with completing this lab? Enter the names of anyone that you assisted with completing this lab. If you did not help anyone, then just type out that you helped no one. No at this time. # Publish Document Click the “Knit” button to publish your work as an html document. This document or file will appear in the folder specified by your working directory. You will need to upload both this RMarkdown file and the html file it produces to AsU Learn to get all of the lab points for this week.