1) Create a Vector with c Function.

This Blog entry is from the Data Structures section in Learn R.

The c function is used to combine variables into a vector.  To create a numeric Vector,  start by typing:

NumericVector <- c(1,2,3,4,5)
creating-a-numeric-vector-using-c-function-in-r.png

Run the line of script to console:

c-function-sent-to-r-console-to-create-a-numeric-vector.png

The vector appears in the environment pane,  showing the dimensions of [1,5],  which would suggest 1 row,  five columns:

numeric-vector-written-to-environment-window-in-rstudio.png

The vector can be referenced in the console, as with all other variables, by typing:

NumericVector
script-entry-to-return-a-numeric-vector-in-r.png

Run the line of script to the console:

numeric-vector-written-out-to-r-console.png

To observe how R handles vectors, comprised of separate types (in so far as it CANT handle it), start by typing:

Mixed <- c(1,2,3,4,”string”)
script-line-to-create-a-vector-of-mixed-types.png

Run the script to console:

mixed-types-vector-in-rstudio-environment-window.png

It can be seen that the vector has been created and is displayed in the environment pane, however, it is being created as a character vector owing to the presence of character argument which cannot be coerced to a numeric value and as such the entire vector becomes a character vector.  To validate this in the console, type:

Mixed
script-to-write-out-mixed-vector-in-r.png

Run the line of script to console:

mixed-vector-has-been-converted-to-string-in-r-console.png

It can be validated that the vector has been created as a string, based on the premise of the double quotations around all of the entries.