Data Frame

Question 1 (On Your Own)

(1 point) Create a character vector named food and have it contain the words “pizza”, “ramen”, and “choco-pie”, in that order. Print the contents of this vector.

# Type your CODE in here

'food' <- c("pizza", "Ramen", "Choco-pie")

Question 2 (On Your Own)

(1 point) Create a numeric vector named freq with the numbers 4, 7, 16, in that order. Print the contents of this vector.

# Type your CODE in here
freq <- c(4,7,16)

Question 3 (On Your Own)

(1 point) Combine the food vector and the freq vector into a data frame called food_diary. Print this data frame.

# Type your CODE in here
food_diary <-data.frame(food, freq)

Question 4 (On Your Own)

(1 point) From the food_diary data frame, extract and print only the food column.

# Type your CODE in here
food_diary <- (food) 
food
## [1] "pizza"     "Ramen"     "Choco-pie"

Importing Data

Question 5 (With Your TA)

(1 point) Using the code from the lab manual, import the data from births.csv into R. Make sure the object is named births.

# Type your CODE in here
setwd("C:/Users/19092/Downloads")
births <- read.csv("births.csv")

Question 6 (With Your TA)

(1 point) Run the command head(births) to print out the first 6 rows of the data frame. Verify that this matches the output of the lab manual.

# Type your CODE in here
head(births) 

Question 7 (On Your Own)

(2 points) Is the Gender variable a categorical or quantitative data type? Why?

The gender variable is a categorical data type because it can be placed into two categories or groups.

Question 8 (On Your Own)

(2 points) Is the Meduc variable a categorical or quantitative data type? Why?

The Meduc variable is quantitative data because is has various numerical outputs as its results.

Descriptive Statistics

Question 9 (On Your Own)

(1 point) Calculate and print the mean of the mothers’ age.

# Type your CODE in here
mean(births$Mage)
## [1] 27.2037

Question 10 (On Your Own)

(1 point) Calculate and print the proportions of the race of the dad.

# Type your CODE in here
tally(births$Racedad, format = "proportion")
## X
##       Asian       Black       Other     Unknown       White 
## 0.023523524 0.161161161 0.008508509 0.186686687 0.620120120

Question 11 (On Your Own)

(1 point) Calculate and print the mean weight of the baby at birth in grams. Use the conversion: 1 ounce = 28.35 grams.

# Type your CODE in here
mean(births$weight)*28.35
## [1] 3290.274