I have a tibble with 27 columns of numeric values. I want to count the number of digits after the decimal point, especially, I want to know the maximum number of digits that can happen in each column.
I tried to convert the numerical values to a string variable, then subset a string after the decimal point, then count the number of the new string, then find max.
afterdecimal_val1 <- data %>%
mutate(
across(where(is.numeric), as.character),
) %>%
rowwise() %>%
mutate(
init = str_split(value_1,"[.]"),
init2 = init[2],
init3 = nchar(init2)
) %>%
ungroup() %>%
mutate(init4 = max(init3, na.rm=TRUE))
Well, this works, however only for the Column "value_1" and I am pretty sure that this is not the prettiest way to do it.
Do you know a more feasible way? Or: Can you help me to upgrade the code so it works for all 27 variables and not only "value_1"?
I really like answers using dplyr!
Thanks for your help!