Home > front end >  How to convert kg to lb and then find the mean and standard deviation?
How to convert kg to lb and then find the mean and standard deviation?

Time:04-12

I'm new with R and Stack Overflow. I am working on a question from the a data that I've been struggle with. The 2015 data comes from https://www.kaggle.com/cdc/behavioral-risk-factor-surveillance-system. It's a large .csv file so I didn't know how to put it on here (my apologizes). And the codebook is from https://www.cdc.gov/brfss/annual_data/2015/pdf/2015_Calculated_Variables_Version4_08_10_17-508c.pdf.

Q. Compare only those who have and have not had some form of arthritis, rheumatoid arthritis, gout, etc. For those groupings, convert reported weight in kilograms to pounds. Then, compute the mean and standard deviation of the newly created weight in pounds variable. Use the conversion 1KG = 2.20462 LBS. Make sure the units are in pounds, not two decimals implied. The names of the variables should be mean_weight and sd_weight. mean_weight should equal 183.04.

It is suppose to look like this:

mean_weight sd_weight
183.04 xx.xx
xxx.xx xx.xx

My code was:

weight_lb <- na.omit((BRFSS2015$WTKG3 * 2.20462)/100)
Model1<- BRFSS2015%>%
  filter(HAVARTH3 == "1" | HAVARTH3 == "2")%>%
  group_by(HAVARTH3)%>%
  summarise(mean_weight = round(mean(weight_lb), digits = 2), sd_weight = round(sd(weight_lb), digits = 2))%>%
  select(mean_weight, sd_weight)
Model1

My Output was:

mean_weight sd_weight
179.42 47.64
179.42 47.64

Please help! Thank you.

CodePudding user response:

Using your code and means na.rm = TRUE argument

library(dplyr)

# options(pillar.sigfig = 7)

BRFSS2015 %>%
  filter(HAVARTH3 == "1" | HAVARTH3 == "2") %>%
  group_by(HAVARTH3) %>%
  mutate(weight_lb = WTKG3 * 2.20462 / 100) %>% 
  summarise(mean_weight = round(mean(weight_lb, na.rm = TRUE), digits = 2), 
            sd_weight = round(sd(weight_lb, na.rm = TRUE), digits = 2)) %>%
  select(mean_weight, sd_weight)

we get

# A tibble: 2 x 2
  mean_weight sd_weight
        <dbl>     <dbl>
1      183.04     49.81
2      176.08     46.31
  •  Tags:  
  • r
  • Related