15) Create a string variable by assignment

This Blog entry is from the Getting Started in R section in Learn R.

Strings in R are surrounded by double quotation marks yet the assignment procedure is the same as numeric assignment.  Start by creating a new line in the script editor and typing:

Char <- "Test"
creating-a-string-variable-by-assign-in-r.png

Run the script to console:

string-variable-created-by-assign-in-rstudio-environment-window.png

The new String value is written to the Environment pane.  The variable is addressable from the script by typing the variable:

String
writing-out-a-string-variable-to-r-console.png

Run the line of script to console:

string-variable-written-out-to-r-console.png

Validate the variable type by using the mode() function. Type into the script pane:

mode(String)
using-the-mode-function-to-determine-string-variable.png

Run the line of script to console:

the-mode-function-return-value-in-r-console.png

It can be observed that the data type was defined as character upon assignment.