Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem : 1. You need to read chol.txt file for this problem. Use “apply” functi

ID: 3572853 • Letter: P

Question

Problem :

1. You need to read chol.txt file for this problem.

Use “apply” function to calculate the overall mean for each variable, except for the sex variable.

Use “aggregate” to calculate the sex-specific mean for each variable.

2. Create a new variable, chol2, which is based on the chol variable from the chol data frame. If chol is greater than the mean of chol, then chol2 = 'Hi'; otherwise, chol2= 'LOW'

Use “tapply” function to calculate the standard deviation of bmi for each chol2 category.

Use “tapply” function to calculate the standard deviation of bmi for each combination of sex and chol2 categories.

chol.txt file as below:

Explanation / Answer


##
## Problem 1
##
# 1. You need to read chol.txt file for this problem.
# Use pply" function to calculate the overall mean for each variable, except for the sex variable.
# Use ggregate" to calculate the sex-specific mean for each variable.
prob1 = read.table("C:/Users/Orysya/Desktop/Introduction_to_R_Programming/Assignment3_W8/chol.txt", header=T)
prob1
apply(prob1[2:12],2, mean, na.rm = T)
sum_by_sex = aggregate(prob1[2:12], by = list(prob1$sex), FUN = mean, na.rm = T)
sum_by_sex
# 2. Create a new variable, chol2, which is based on the chol variable from the chol data frame. If chol is greater than the mean of chol, then chol2 = `Hi'; otherwise, chol2= `LOW'
# Use apply" function to calculate the standard deviation of bmi for each chol2 category.
# Use apply" function to calculate the standard deviation of bmi for each combination of sex and chol2 categories.
A = apply(prob1[3], 2, mean, na.rm=T)
A
chol2 <- ifelse(prob1$chol > A, "Hi", "Low")
chol2
prob1["chol2"] <- chol2
prob1
B = tapply(prob1$bmi, prob1$chol2, sd)
B
C = tapply(prob1$bmi, list(prob1$sex, prob1$chol2), sd)
C

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote