convert <- tribble(
~id, ~char_num, ~num_val,
"1", "100", 55,
"2", "200", 60,
"3", "ABC", 65,
"4", "300", NA,
"5", NA, 75 )
convert2 <- convert %>%
mutate( char_to_num = as.numeric(char_num),
num_to_char = as.character(num_val)
)
- The dataset `convert` includes both character and numeric values with intentional missing and invalid entries.
- `as.numeric(char_num)` converts `char_num` to numeric.
- Non-numeric text like 'ABC' becomes `NA`. `as.character(num_val)` converts numeric values to character strings.
- The new columns `char_to_num` and `num_to_char` reflect these conversions.