As far as I know, what most languages call a string, R calls a character vector. For example, "Alice"
is not a string, it's a character vector of length 1. Similarly, c("Alice", "Bob")
is a character vector of length 2. I cannot recall my IDE or any of my work with R's type system telling me that R has any internal concept of "strings".
Despite this, R's documentation frequently uses the word "string":
?paste
and ?nchar
frequently talk of "character strings". ?paste
, ?chartr
, and ?agrep
.?strsplit
mentions "substrings". ?agrep
, ?toString
, and ?adist
talk about strings both in their titles and "Description" sections. strsplit
, strwidth
, and toString
have string or a shorthand for it in their names. So does R actually have a concept of strings, or does it always mean exactly the same thing as "character vector"?
Converting my comment to an answer.
A description of character
and string can be found in the R Language Definition :
R has six basic ('atomic') vector types: logical, integer, real, complex, string (or character) and raw. The modes and storage modes for the different vector types are listed in the following table.
typeof | mode | storage.mode |
---|---|---|
logical | logical | logical |
integer | numeric | integer |
double | numeric | double |
complex | complex | complex |
character | character | character |
raw | raw | raw |
[...]
String vectors have mode and storage mode
"character"
. A single element of a character vector is often referred to as a character string .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.