Convert uppercase to lowercase

Hello community!

I have a dataframe where all characters are in uppercase. What options do you recommend to convert it to lowercase?

Thank you for your help.

Hello,

I would use the str_to_lower function from the stringr package to do this.

Here is an example:

# loading packages
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(stringr)
library(tibble)

# creating fake data
fake_data <- tibble(
  char_1 = replicate(n = 100, expr = paste0(sample(x = LETTERS, size = 10, replace = TRUE), collapse = "")),
  char_2 = replicate(n = 100, expr = paste0(sample(x = LETTERS, size = 10, replace = TRUE), collapse = "")),
  char_3 = replicate(n = 100, expr = paste0(sample(x = LETTERS, size = 10, replace = TRUE), collapse = ""))
)

# converting character data to lowercase
fake_data |>
    mutate(across(.cols = where(is.character), .fns = str_to_lower))
#> # A tibble: 100 Γ— 3
#>    char_1     char_2     char_3    
#>    <chr>      <chr>      <chr>     
#>  1 tlybnwoxvb bsdmjylqnn zooowlavdx
#>  2 lmtwfashdx jbmipkwzsf qzdmfqvviz
#>  3 vmdbclanzs xoogmwqrzj ifokfyxqgn
#>  4 qlyumyaemg xzlewkwqwm xytnofxzyl
#>  5 wresynkvdf nqvrmsaygx ssfjumdaic
#>  6 cklucwlkfv ffpbtypvsw xlczqbriut
#>  7 dhmphycdow ofdiepfrte dcwryurron
#>  8 vdglaygngj txlgjypwbd wvgainofez
#>  9 hrejxaydos opxqlcosls svvxpzapch
#> 10 mzlkdosfkn gohkxpzpwv hfbzfelnzk
#> # β„Ή 90 more rows

Created on 2025-10-16 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.1 (2025-06-13)
#>  os       macOS Sequoia 15.6.1
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Toronto
#>  date     2025-10-16
#>  pandoc   3.6.3 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
#>  quarto   1.7.31 @ /usr/local/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  cli           3.6.5   2025-04-23 [1] RSPM
#>  digest        0.6.37  2024-08-19 [1] RSPM
#>  dplyr       * 1.1.4   2023-11-17 [1] RSPM
#>  evaluate      1.0.5   2025-08-27 [1] RSPM
#>  fastmap       1.2.0   2024-05-15 [1] RSPM
#>  fs            1.6.6   2025-04-12 [1] RSPM
#>  generics      0.1.4   2025-05-09 [1] RSPM
#>  glue          1.8.0   2024-09-30 [1] RSPM
#>  htmltools     0.5.8.1 2024-04-04 [1] RSPM
#>  knitr         1.50    2025-03-16 [1] RSPM
#>  lifecycle     1.0.4   2023-11-07 [1] RSPM
#>  magrittr      2.0.4   2025-09-12 [1] RSPM
#>  pillar        1.11.1  2025-09-17 [1] RSPM
#>  pkgconfig     2.0.3   2019-09-22 [1] RSPM
#>  R6            2.6.1   2025-02-15 [1] RSPM
#>  reprex        2.1.1   2024-07-06 [1] RSPM
#>  rlang         1.1.6   2025-04-11 [1] RSPM
#>  rmarkdown     2.30    2025-09-28 [1] RSPM
#>  rstudioapi    0.17.1  2024-10-22 [1] RSPM
#>  sessioninfo   1.2.3   2025-02-05 [1] RSPM
#>  stringi       1.8.7   2025-03-27 [1] RSPM
#>  stringr     * 1.5.2   2025-09-08 [1] RSPM
#>  tibble      * 3.3.0   2025-06-08 [1] RSPM
#>  tidyselect    1.2.1   2024-03-11 [1] RSPM
#>  utf8          1.2.6   2025-06-08 [1] RSPM
#>  vctrs         0.6.5   2023-12-01 [1] RSPM
#>  withr         3.0.2   2024-10-28 [1] RSPM
#>  xfun          0.53    2025-08-19 [1] RSPM
#>  yaml          2.3.10  2024-07-26 [1] RSPM
#> 
#>  [1] /Users/timothychisamore/Library/R/x86_64/4.5/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.5-x86_64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

All the best,

Tim

Adding to Tim’s reply, you can also use base R and {tidyverse} to achieve this!

Base R

# Convert a single column
df$col <- tolower(df$col)

# Convert all character columns
df[] <- lapply(df, function(x)
  if(is.character(x)) tolower(x) else x)

Tidyvers

df <- df %>%
  mutate(across(where(is.character), tolower))

Best,

Luis

1 Like