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. In this lab you will also need to describe your results. Don’t forget that you need to acknowledge if you used any resources beyond class materials or got help to complete the assignment.
Instructions associated with this assignment can be found in the file “DescribingDataTutorial.html”. You can find the code book associated with the BBQ data on the AsULearn.
The data set you will use is different than the one used in the instructions. Pay attention to the differences in the Excel files name, any variable names, or object names. You will need to adjust your code accordingly.
Once you have completed the assignment, you will need to knit this R Markdown file to produce an html file. You will then need to upload the .html file and this .Rmd file to AsULearn.
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 9 and 10).
You need to identify and set your working directory in this section. If you are working in the cloud version of RStudio, enter a note here to tell us that you did not need to change the working directory because you are working in the cloud.
getwd()
## [1] "/Users/Saniyaaa/Desktop/Research Methods Lab/DescribingDataFall2025"
setwd("/Users/Saniyaaa/Desktop/Research Methods Lab/DescribingDataFall2025")
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
You need to install and load the packages and data set you’ll use for
the lab assignment in this section. In this lab, we will use the three
packages we have used in previous labs (dplyr
,
tidyverse
, and openxls
) and one new package
(modeest
). Remember, the first time you use a package you
need to install the package.
install.packages("modeest")
##
## The downloaded binary packages are in
## /var/folders/32/zb9p7dwj18l3xms644qqhmv80000gs/T//RtmpX4z67O/downloaded_packages
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
library("modeest")
library("openxlsx")
Example_BBQData <- read.xlsx("DescribingDataAssignmentData.xlsx")
Display the names of the variables in your data set.
names(Example_BBQData)
## [1] "Observation" "Sex" "Age"
## [4] "Hometown" "Favorite.Meat" "Favorite.Sauce"
## [7] "Sweetness" "Favorite.Side" "Restaurant.City"
## [10] "Restaurant.Name" "Minutes.Driving" "Sandwich.Price"
## [13] "Dinner.Plate.Price" "Ribs.Price"
Display the last 5 observations in the data set.
Choose one variable other than Dinner.Plate.Price and display all the observations for that variable.
mean(Example_BBQData$Dinner.Plate.Price)
## [1] NA
You need to calculate the means for variables measuring 1) the price of a dinner plate, 2) preferred sweetness of sauce, 3) how long the respondent is willing to drive, and 4) the price of a rib plate. Calculate the means of each variable separate chunks of code (that is, you’ll need four distinct chunks of code). After each chunk of code, write a one sentence description of the mean. Don’t forget about missing data.
mean(Example_BBQData$Dinner.Plate.Price, na.rm=TRUE)
## [1] 19.74563
Recalculate the means, but round the calculated values. Again, use a separate chunk for each rounded mean. After each chunk of code, write a one sentence description of the mean. Don’t forget about missing data. Importantly, you need to round the means of the different variables to different decimal places.
The price of a dinner plate should be rounded to the 2nd decimal place.
Sweetness of sauce should be rounded to the 1st decimal place.
How long the respondent is willing to drive should be rounded to the 3rd decimal place.
The price of a rib plate should be rounded to the 2nd decimal place.
round(mean(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE),digits=2)
## [1] 19.75
mean_plate <- mean(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE)
print(mean_plate)
## [1] 19.74563
mean_plate
## [1] 19.74563
round_mean_plate <- round(mean_plate,digits=2)
print(round_mean_plate)
## [1] 19.75
You need to calculate and describe the medians of the variables measuring 1) age of the respondent, 2) how long the respondent is willing to drive for good BBQ, and 3) the price of a sandwich. Use a separate chunk of code for each variable. After each chunk of code write one sentence description of the median. Don’t forget about missing data.
median(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE)
## [1] 18
You need to calculate and describe the modes of the variables for 1) favorite meat, 2) favorite sauce, and 3) favorite side. These are all categorical variables. Use a separate chunk of code for each variable. After each chunk of code write one sentence description of the mode.
When describing these results, you need to convert the numerical modes of the different variables into words according to the survey code book, which is available on AsU Learn.
mfv(Example_BBQData$Dinner.Plate.Price)
## [1] 15
You need to calculate and describe the ranges, maximums, and minimums of the variables that identify respondents’ 1) ages, 2) rib price, and 3) how many minutes they would drive for BBQ. Use a separate chunk of code for each variable. After each chunk of code write a one sentence description of the minimum, maximum, and range.
min(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE)
## [1] 0
max(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE)
## [1] 69
max(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE) - min(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE)
## [1] 69
You need to calculate and describe the standard deviation of the variables that identify 1) the number of minutes a respondent would drive for BBQ and 2) the price they would pay for a sandwich in this section.
sd(Example_BBQData$Dinner.Plate.Price, na.rm = TRUE)
## [1] 9.164569
mean(Example_BBQData$Favorite.Meat, na.rm = TRUE)
## [1] 2.243789
mfv(Example_BBQData$Favorite.Meat)
## [1] 1
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. - No one helped me.
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. - Not as of now.
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.