Character Type
Character values are pieces of text, like words or sentences, written inside quote marks. They are how R keeps names and messages.
In this page:
Syntax
text <- "some text"
class(text) # "character"
Character Type
R's character type stores text strings, written with single or double quotes. Unlike some languages, there's no separate single-character type -- a one-letter string is still character.
String concatenation and formatting typically go through paste() rather than a + operator.
Note:
Single and double quotes work identically for strings in R -- pick one style and stay consistent.
Example: Character Type
name <- "Ada"
greeting <- 'Hello'
cat(class(name), "\n")
cat(greeting, name, "\n")
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
Common Mistakes
- Forgetting the quotes around text, as in
name <- Ada, which looks for a variable namedAdaand fails. - Trying to add strings with
+, as in"a" + "b", which is an error; usepaste(). - Mixing up a mismatched pair of quotes such as
"Hello', which leaves the string unclosed.
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: