R Strings
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.
str1 = "Arjun"'"s book."
- To include a double quote inside a string value, surround the double quote with single quotes.
str1 = "Arjun says, '"'Hello World'"'"
- Single quote or double quote could be included at the starting or ending of the string value as is.
str1 = "'Hello""
R String Operations
- R – Concatenate two or more Strings
- R – Find length of String
- R – Find Substring of a String
- R – Convert String to Upper-case
- R – Convert String to Lower-case
Conclusion
In this R Tutorial, we have learnt about Strings, rules to define them, and different useful operations on Strings.