Introduction to Vectors in R

A key component of R is the use of vectors. Vectors a single piece of information that contents a collection of information. This probably sounds extremely confusing so an example will be provided.

Think of an organization such as a school. We will call the school Asia International School. Asia International school consist of an administrator named Dr. T, teachers named Mr. Bob and Mrs . Smith, and students named Sam, David, and Mary. In this example, the school is consider a vector or a single piece of information (Asia International School). The administrators, teachers, and students are the collection of information within the large piece of information that is the school.

If we wanted to write this example using the R programming language it would look something like the following…

  • > Asia International School(Dr. T, Mr. Bob, Mrs. Smith, Sam, David, Mary)
    [1] Dr. T Mr. Bob Mrs. Smith Sam David Mary

To be fair this is not exactly how it is done this is strictly an imperfect illustration of a very abstract concept.

A Real Example

In order to make a vector in R you need to use c() function. A function is a piece of code that does something to the information that is within its parentheses. For example, let’s make a vector that contains the numbers 1, 2, 3, 4, 5.

  • > c(1,2,3,4,5)
    [1] 1 2 3 4 5

To get the second line you need you press enter

The c means combine. The information inside the parentheses is the information that is being combined into one vector. Going back to our school example, Dr. T, Mr. Bob, Mrs. Smith, Sam, David, and Mary were being combined into the school Asia International. In a vector, all information inside the parentheses is known as arguments.


This is just some of the most basic ideas about vectors. There is a great deal more to explore about the use of vectors which is considered one of the most powerful features of R. The challenge of learning R is with the abstract nature of programming. You have to think of things you want to do in terms of a code that the computer can understand. This is very confusing for most people.


13 thoughts on “Introduction to Vectors in R

  1. Pingback: Making and Using Variables in R | educationalresearchtechniques

  2. Pingback: Basics of Vectors Functions in R | educationalresearchtechniques

  3. Pingback: Doing Simple Math in R | educationalresearchtechniques

  4. Pingback: Introduction to Vectors in R: Part IIW | educationalresearchtechniques

  5. Pingback: Introduction to Vectors Part III: Logical Vectors and More | educationalresearchtechniques

  6. Pingback: Introduction to Character Vectors in R | educationalresearchtechniques

  7. Pingback: Introduction to Factors in R | educationalresearchtechniques

  8. Pingback: Beyond Vectors: Introduction to Matrices and Arrays in R | educationalresearchtechniques

  9. Pingback: Data Frames in R: Part I | educationalresearchtechniques

  10. Pingback: Introduction to Vectors in R | Education and Re...

  11. Pingback: Switch Function in R | educationalresearchtechniques

  12. Pingback: Using ‘for’ Loops in R | educationalresearchtechniques

  13. Pingback: Apply Functions in R | educationalresearchtechniques

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s