# Investigate the data set women, which is # part of base R. ?women # A. Use the function str() to list the class of the data set, # the number of observations and variables, along with # the variable names and types # B. List the first 10 lines of the data set # C. Write an R function to calculate BMI rounded to one decimal place value. # The formula for BMI is (weight / height^2)*703 # Use the function, round(), to round the calculated BMI # to one decimal place value ?round() # D. Test your BMI function: # for weight = 145 lbs, height = 64 inches (BMI should be 24.9) # for weight = 130 lbs, height = 66 (BMI should be 21) # E. Calculate the BMI for the women in the data set, women and # save these values in a new variable, bmi. # The new variable, bmi, should be a included as a new variable # in the data frame, women. # Check: Print the first and last 5 rows of the data frame, women # F. Use the summary() function to find the Minimum, Quartile 1 (Q1), # Median/Quartile 2 (Q2), Quartile 3 (Q3) and Maximum values of bmi # G. Convert the numeric variable, bmi, into the factor bmi.quartiles # using the function cut( ) and the following values as # breaks: Minimum, Quartile 1 (Q1), Median/Quartile 2 (Q2), # Quartile 3 (Q3), Maximum # The new variable, bmi.quartiles, should be included # as a new variable (column) in the women data frame # NOTE: Review Lecture 6 Class Notes - # Converting continuous variables to categorical variables ### IMPORTANT NOTE: Set the cut() function argument, include.lowest = TRUE ?cut() # CHECK: That the variable, bmi.quartiles, has been computed correctly and # added to the data frame, women # H. Use the table( ) function to generate # a frequency table for bmi.quartiles RSTUDIO
# Investigate the data set women, which is # part of base R. ?women # A. Use the function str() to list the class of the data set, # the number of observations and variables, along with # the variable names and types # B. List the first 10 lines of the data set # C. Write an R function to calculate BMI rounded to one decimal place value. # The formula for BMI is (weight / height^2)*703 # Use the function, round(), to round the calculated BMI # to one decimal place value ?round() # D. Test your BMI function: # for weight = 145 lbs, height = 64 inches (BMI should be 24.9) # for weight = 130 lbs, height = 66 (BMI should be 21) # E. Calculate the BMI for the women in the data set, women and # save these values in a new variable, bmi. # The new variable, bmi, should be a included as a new variable # in the data frame, women. # Check: Print the first and last 5 rows of the data frame, women # F. Use the summary() function to find the Minimum, Quartile 1 (Q1), # Median/Quartile 2 (Q2), Quartile 3 (Q3) and Maximum values of bmi # G. Convert the numeric variable, bmi, into the factor bmi.quartiles # using the function cut( ) and the following values as # breaks: Minimum, Quartile 1 (Q1), Median/Quartile 2 (Q2), # Quartile 3 (Q3), Maximum # The new variable, bmi.quartiles, should be included # as a new variable (column) in the women data frame # NOTE: Review Lecture 6 Class Notes - # Converting continuous variables to categorical variables ### IMPORTANT NOTE: Set the cut() function argument, include.lowest = TRUE ?cut() # CHECK: That the variable, bmi.quartiles, has been computed correctly and # added to the data frame, women # H. Use the table( ) function to generate # a frequency table for bmi.quartiles RSTUDIO
- Use the str() function to get information about the women dataset
- Use head() function to display the first 10 rows of the women dataset
- Define a function to calculate BMI using the formula: (weight / height^2)*703, and round the result to one decimal place using the round() function
- Test the BMI function using two sets of weight and height values
- Calculate the BMI for each woman in the dataset and add it as a new variable, bmi, to the women dataset
- Use the summary() function to get basic statistical information about the bmi variable in the women dataset
- Convert the bmi variable to a factor variable, bmi.quartiles, using the cut() function and specified breaks, and add it as a new variable to the women dataset
- Use the table() function to get a frequency table for the bmi.quartiles variable in the women dataset.
Step by step
Solved in 4 steps with 5 images