CodeInfoNet

Learn programming on the go!

Home » Introduction to Vector in R

Introduction to Vector in R

In this article I am going to write about the vector in R. Main objective of this article to get familiar with the concept of vectors in R programming language.

We will touch down the following topics:

-What is Vector?

-Creating our first vector in R

In previous articles we understood the loop structures and conditional statements. Also we have seen the practical implementation of the law of large numbers. You can always read those articles to refresh your knowledge before proceeding further.

Now let’s see what we have in this article.

What is vector?

To define a vector we can say that, a vector is a sequence of data elements of the same basic type. Vector is R is same as the Array in C, C++. Just the basic difference between the vector and the array is, array index starts from 0 and index of vector in R starts with 1 making it much easier. To learn more about array click here.

Vector can be of any type. You can create vector of numbers or you can also create vector of characters.

If you store a number in character vector, R will automatically convert it to a character and it is represented as a character. That’s because vector can have data elements only of same type.

Below image shows the numeric as well as character vector.

Vectors In R
Vectors In R

Now I am going to tell all of my readers the most amazing secret about R (May be some of you are aware of it.)

“In R programming, even a single number or a single character is stored as a vector.”

So basically everything in R is a vector. Hence vector is the most important part in the R programming language.

In next article I will show you how to create the vector.

Thanks for reading. Keep reading.

Don’t forget to let me know about the flaws in any article. Feel free to comment or reach us directly via mail. Also you can reach us on Facebook, linkedin, twitter, instagram any of the platform you feel comfortable with.

[wpforms id=”22″]

Sumit Rajguru

Back to top