OneBite.Dev - Coding blog in a bite size

convert a string to lowercase in R

Code snippet on how to convert a string to lowercase in R

  x <- "THIS IS A STRING"
  x <- tolower(x)

This code takes a string, “THIS IS A STRING”, and converts all capital letters to lowercase letters. The first line of code creates a variable ‘x’ and assigns it the value “THIS IS A STRING”. The second line calls the R command ‘tolower’. This function takes ‘x’ and converts any capital letters to lowercase letters. The second line then reassigns the lowercase value to ‘x’, overwriting the original string and storing the lowercase string instead.

r