I'm trying to apply modify_if function to a dataframe with character values:
> dataframe
col_1 col_2 col_3
<chr> <chr> <chr>
1 840 1097 989
2 s s s
3 781 9021 9006
I would like to insert thousands separator in character columns to get the following result:
> expected_dataframe
col_1 col_2 col_3
<chr> <chr> <chr>
1 840 1 097 989
2 s s s
3 781 9 021 9 006
I don't know how to call the cells in the predicate function. I tried to use nchar function but I'm facing the following error:
> modify_if(dataframe, ~ nchar(.x) >3 , ~ stri_sub( ., nchar() - 3, nchar() - 2) <- " " )
Error: Predicate functions must return a single `TRUE` or `FALSE`, not a logical vector of length 102