I would like to convert a height variable I have from character type to numeric. for context, this is so I can use the values to calculate body mass index.
Looking at the below example data frame, I would like to convert Height_1 into Height_2 (whereby Height_2 is in inches):
# Height_1 Height_2
# 5ft6in 66
# XftXin XXXX
# XftXin XXXX
# XftXin XXXX
# XftXin XXXX
I have tried a few things using the "tidyverse" and "measurements" packages but have not been able to create a variable like Height_2 above. For example:
library(dplyr)
library(tidyr)
df %>%
separate(Height_1,c('feet', 'inches'), sep = 'ft', convert = TRUE, remove = FALSE) %>%
mutate(Height_2 = 12*feet + inches)
I think this is because the above doesn't address the fact that there is "in" at the end of the values.