R Course

Strings

Go back

There is no concatenation operator in R, use the paste function.

paste("Hello", "World");
# merge a vector of strings with the separator "\n"
paste(s1, ..., collapse = "\n")
# merge strings with the separator "\n"
paste(s1, ..., sep = "\n")

Other functions

  • print: print
  • cat: concatenate and print
  • substring: substr
  • strsplit: split string
  • nchar: length
  • toupper, tolower
  • gsub: tr (=replace char)
  • trimws: trim (remove useless spaces at the start and the end)