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.
Conclusion
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.
Pingback: Making and Using Variables in R | educationalresearchtechniques
Pingback: Basics of Vectors Functions in R | educationalresearchtechniques
Pingback: Doing Simple Math in R | educationalresearchtechniques
Pingback: Introduction to Vectors in R: Part IIW | educationalresearchtechniques
Pingback: Introduction to Vectors Part III: Logical Vectors and More | educationalresearchtechniques
Pingback: Introduction to Character Vectors in R | educationalresearchtechniques
Pingback: Introduction to Factors in R | educationalresearchtechniques
Pingback: Beyond Vectors: Introduction to Matrices and Arrays in R | educationalresearchtechniques
Pingback: Data Frames in R: Part I | educationalresearchtechniques
Pingback: Introduction to Vectors in R | Education and Re...
Pingback: Switch Function in R | educationalresearchtechniques
Pingback: Using ‘for’ Loops in R | educationalresearchtechniques
Pingback: Apply Functions in R | educationalresearchtechniques