Introduction
Character type stores text like words or sentences so you can work with letters and words in your program.
my_text <- "Hello, world!" # or single quotes also work my_text <- 'Hello, world!'
name <- "Alice"greeting <- 'Good morning!'empty_string <- ""single_char <- "A"name <- "Bob" greeting <- "Hello" message <- paste(greeting, name) print(message)
"hello" uses quotes correctly to create a character string."Hello" and "World" in R?paste() is used to join strings with a space by default.paste("Hello", "World") uses the correct function paste() to join strings.text <- "R is fun" substr(text, 1, 3)
words <- c(hello, "world", "R")
hello is unquoted.hello causes R to look for a variable named hello, which likely does not exist.hello -> Option Dc("apple", "banana", "cherry"). How do you create a single character string with these words separated by commas and a space, like "apple, banana, cherry"?collapse argument joins vector elements into one string separated by the given string.paste(c("apple", "banana", "cherry"), collapse=", ") correctly uses paste() with collapse=", " to join words with comma and space.sep controls separator between arguments, not vector elements; collapse is needed here.Pass the test and this pattern moves unknown