Write Calculating a mean The Walker Family has five sisters. In order of age, their heights are 1.72, 1.48, 1.45, 1.91, and 1.53 meters. Write an expression that calculates the average height of the five women, in meters. You should only need to use (, ), /, and + along with numbers to solve this.
sisters_height = c(1.72,1.48,1.45,1.91,1.53)
mean(sisters_height)
## [1] 1.618
#or
mean_sisters_height = sum(sisters_height)/length(sisters_height)
mean_sisters_height
## [1] 1.618
Converting dimensions. There are 3.281 feet per meter. Calculate the number of feet of the average height of the women. You should do this by taking the expression for part 1 and adding the necessary additional operations to do this conversion.
feet = 3.281
mean_sisters_height_feet = mean_sisters_height * feet
mean_sisters_height_feet
## [1] 5.308658
Use the div-by-1 operator to extract the foot portion of the average height of the Walker sisters calculated in part 2. Then use the mod-by-1 operator to extract the decimal portion of the average height in feet, and convert this to inches. Caution: mod and div have a higher order of precedence than multiplication–they take place first. Be sure to use proper parenthesis to get the right answer. What is the average height of the women in feet-and-inches?
feet_height_inches = (mean_sisters_height_feet %/% 1) * 12
foot_portion = (mean_sisters_height_feet %% 1) * 12
feet_and_inches = feet_height_inches + foot_portion
print(c("Walker's women height average in feet and inches is:",mean_sisters_height_feet, "and", feet_and_inches), quote = F)
## [1] Walker's women height average in feet and inches is:
## [2] 5.308658
## [3] and
## [4] 63.703896
Tom_cruise = 172.1
Billie_Eillish = 160
Jason_Momoa = 193
Cardi_B = 154.9
Post_Malone = 184.2
Khloe_Kardashian = 174
# just insert the "name" and actor name variable in the function
height_in_Walkers = function(name_in_brackets,name) {
Walkers_height_inches = 63.703896
cm_to_inches = name * 0.393701 ;
height = cm_to_inches / Walkers_height_inches;
height_name = c(name_in_brackets, 'is', height, "Walker's tall")
return (height_name)
}
height_in_Walkers("Cardi_B",Cardi_B) # or height_in_Walkers("Cardi_B",154.9)
## [1] "Cardi_B" "is" "0.957308559275558"
## [4] "Walker's tall"
#question 5
team_1 = c(Tom_cruise,Cardi_B,Khloe_Kardashian); team_2 = c(Post_Malone, Jason_Momoa, Billie_Eillish)
mean_team_1 = mean(team_1);mean_team_2 = mean(team_2)
height_in_Walkers('Team 1', mean_team_1)
## [1] "Team 1" "is" "1.03208863395105" "Walker's tall"
height_in_Walkers('Team 2', mean_team_2)
## [1] "Team 2" "is" "1.10666270291119" "Walker's tall"
#team 2 will probably crash team 1