Single quotes or double quotes are used to represent Strings in R programming language. We shall learn rules to write a String, embed special characters in it, and some of the common operations like concatenation of two strings, finding length of string, etc.
Rules to write R Strings
Following are the rules to write a valid string in R programming language :
- Either single quotes or double quotes should be used to enclose a string value.
str1 = ‘Hello‘
str2 = “Hello“
- As only single quote or double quotes are the special characters used to represent an R string, to include them in a String requires special care.
- To include a single quote inside a string value, surround the single quote with double quotes.
For Who’s hello is that?
str1 = “Who”‘“s hello is that?”
- To include a double quote inside a string value, surround the double quote with single quotes.
For R says, “Hello”.
str1 = “R says, ‘“‘Hello’“‘.”
- Single quote or double quote could be included at the starting or ending of the string value as is.
str = “‘Hello.““
R String Operations
- Concatenate two or more Strings in R
- Find length of String in R
- Extract Substring from a String in R
In this R Tutorial, we have learnt about Strings, rules to define them, and different useful operations on Strings.