0
0
R Programmingprogramming~5 mins

Character (string) type in R Programming

Choose your learning style9 modes available
Introduction
Character type stores text like words or sentences so you can work with letters and words in your program.
When you want to save a person's name in your program.
When you need to store a sentence or message to show later.
When you want to keep track of labels or categories like 'red', 'blue', or 'green'.
When you read text data from a file or user input.
When you want to combine or change words in your code.
Syntax
R Programming
my_text <- "Hello, world!"

# or single quotes also work
my_text <- 'Hello, world!'
Use double or single quotes to create character strings.
Everything inside the quotes is treated as text.
Examples
Stores the word Alice as a character string.
R Programming
name <- "Alice"
Stores a sentence as a character string.
R Programming
greeting <- 'Good morning!'
Creates an empty character string with no letters.
R Programming
empty_string <- ""
Stores a single letter as a character string.
R Programming
single_char <- "A"
Sample Program
This program joins two character strings with a space and prints the result.
R Programming
name <- "Bob"
greeting <- "Hello"
message <- paste(greeting, name)
print(message)
OutputSuccess
Important Notes
In R, character strings are always inside quotes.
Use the paste() function to join strings with spaces.
Empty strings "" are useful when you want a blank text value.
Summary
Character type stores text inside quotes.
Use character strings to work with words and sentences.
You can join strings using paste() to make new messages.