← Back to R Course | Chapter 2: Variables & Types | Lesson 4 of 7

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:

  1. Character Type
Syntax
r
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

markup
name <- "Ada"
greeting <- 'Hello'

cat(class(name), "\n")
cat(greeting, name, "\n")
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
  1. Forgetting the quotes around text, as in name <- Ada, which looks for a variable named Ada and fails.
  2. Trying to add strings with +, as in "a" + "b", which is an error; use paste().
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.