'How to align values of a column right in a data frame in r

I was trying to take the mean of rows, but when I ran the below, it gave me an error.

thetable = thetable %>% 
  rowwise() %>% 
  mutate('2020rate'=mean(c_across(98:109)))

Error in `mutate()`:
! Problem while computing `2020rate = mean(c_across(98:109))`.
i The error occurred in row 1.
Caused by error in `stop_vctrs()`:
! Can't combine `Jan 2020` <double> and `Mar 2020` <character>.
Run `rlang::last_error()` to see where the error occurred.

I looked at the row in question, and it turns out that the entire column is left aligned, while the rest of the data is right aligned.

data frame:

Jan2020  Feb2020  Mar2020  Apr2020
      5        3  2              2
      3        4  5              3

I saw a method to use gt(), but this turns it into an unreadable data frame. Is there another way to align all column values right?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source