R Strings

  • A string is a sequence of characters
  • Strings may be represented by either single quotes (') or double quotes (").

Assigning Strings to a variable

assinging strings to a variable are done using <- operator and the string

Using Single and Double Quotes

Multiple Line String and cat()

As you can see, there is “\n” at the end of each line. This is called an escape character. the n indicates a new line

cat(): Concatenate

String Length: nchar()

To find the length of a string, use the nchar()

Combine String (concatenate): paste()

grepl() in R

  • In R, grepl() is a function that is used for pattern matching in character strings.
  • The name “grepl” stands for “global regular expression pattern match” and it returns a logical vector indicating whether a particular pattern or regular expression is present in each element of a character vector.

Syntax

Example

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top