I have a file with large range of non-standardised mixed imperial and metric measurements, which I want to standardise and republish.
A sample of that range looks like this:
df <- data.frame(Measurements =c("1.25m", "2 Feet", "3 Inches", "5.5 cm"))
|Measurements|
|1.25m |
|2 Feet |
|3 Inches |
|5.5 cm |
which I want to look like this:
|Measurements|MM_Conversion|
|1.25m |1200mm
|2 Feet |609.6mm
|3 Inches |76.2mm
|5.5 cm |55mm
I can't use measurements::conv_unit
or units::set_unit
because they both seem to require numeric input values. Is there a straightforward way of doing this which can parse both the value and the string, and convert accordingly?
EDIT 1: Having an issue whereby Conv_Unit can't convert NA values. If the initial vector instead was: df <- data.frame(Measurements =c(NA, 1.25m", "2 Feet", "3 Inches", "5.5 cm"))
, how would you get around it?