I think you need to fundamentally do your work in a different way.
numeric data should be numeric and character information should be character.
Mashing everything together as character and expecting to easily numerically compute on it is naive. Seperate your data by type at the earliest opportunity.
I don't understand if the data has reached you in this integrated way, or whether you have decided to integrate it. If the latter , then just rethink that choice.
if the former, you would untangle the data something like:
library(tidyverse)
(test <- tibble::tribble(
~V1, ~V2, ~V3, ~V4, ~V5, ~V6, ~V7, ~V8, ~V9, ~V10, ~V11, ~key,
"abc", "abc", "abc", "abc", "abc", "abc", "abc", "abc", "abc", "abc", "abc", NA,
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1",
"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1",
"2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "2", "1",
"3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "3", "0.5",
"4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "4", "1",
"5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "5", "0.3",
"6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "6", "0.7",
"7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "1",
"8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "8", "1",
"9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "0.5"
))
test_2 <- mutate(test,
rn=row_number())
(chartop <- filter(test_2,is.na(key)))
(numbottom <- filter(test_2,!is.na(key)) %>%
mutate(across(where(is.character),as.numeric)))
(comput_bottom <- mutate(numbottom,
across(starts_with("V"),~.*key)))