Substrings

Example

 student_performance <- read.csv("https://raw.githubusercontent.com/kunal0895/RDatasets/master/Moody2018.csv")

 # Have a look at the data
 head(student_performance)

 # Sometimes we want to trim the descriptions to fit the data labels into plots.
 # Here we are trying to extract only the first 4 letters from the column LEAVES_EARLY
 student_performance$LEAVES_EARLY <-substring(student_performance$LEAVES_EARLY, 1,4)

 # Of course, we can also omit the first few letters.
 # Here we omit the first 3 letters of the column ON_SMARTPHONE
 student_performance$ON_SMARTPHONE <-substring(student_performance$ON_SMARTPHONE, 4)
 head(student_performance)