**We will learn:**1. Vectors

2. Sequence Vectors

3. Vector Access

**Details:**In

**R Programming**, R handles many data types; such as, scalars, vectors (numerical, character/strings, logical), data frames, matrices, and lists. (as we learn in Introduction to R Programming Language For Beginner page). However, in this chance, we'll discuss about Vectors.

###
**A. Vectors**

When using vectors in R, we need to have the

**same data types**, as follows:

> c(1,9,5)

Result: [1] 1 9 5

From the example above, we see that 1, 9 and 5 has the same data type. Note that

__is short for word "__

**c**__". It combines (the same) values inside__

*combine*__'s braces.__

**c**When

__has different values of data types, it would shows all in strings data type. See below!__

**c**> c(7,"Hello",FALSE)

Result: [1] "7" "Hello" "FALSE"

Now, let's go more details about Vectors.

###
**B. Sequence Vectors**

Vectors also handles

*sequence values*as in

__functions.__

**c***e.g. c(1,2,3,4,5)*.

The sequence value vector can be written as follows:

> c(5:7)

Result: [1] 5 6 7

That means, when you write: 5:7, R will give the output 5 6 and 7. This is the way for you to order numbers in R. Other method to call the data inside braces which has the same function as in

__, namely,__

**c**__.__

**seq**For example:

> seq(5:7)

Result: [1] 5 6 7

When you input values that

*less then*1 in the back of that value, e.g. seq(5,7,

**0.5**), etc., the last value (

**0.5**) will be added up to each value:

> seq(5,7,0.5)

[1] 5.0 5.5 6.0 6.5 7.0

How is it done?

*See this following illustration!*

From the illustration we can see where 5 must reach 7 by adding 0.5.

When the value has 7 to 5 as in:

7:5

*or*,

> seq(7:5)

Result: [1] 7 6 5

###
**C. Vector Access**

*Store Variable inside Vector C*

__c.1.__Now we will store vector value inside a variable. Let's take one variable, say,

**wordlist**. Here,

**wordlist**will store 3 values inside

__vector.__

**c**Example:

> wordlist <- c('I', 'learn', 'R-language')

If we order (

*as well as*R interprets) the value, that will be like this:

I = 1

learn = 2

R-language = 3

Then, we try to pick number 2 of the values.

Type like this!

> wordlist [2]

Then, R will give you the result:

[1] "learn"

From the example above we can see that the variable

**wordlist**stores

__vector value;__

**c***I*,

*learn*and

*R-language*. In R, the

*three*will be ordered into 1, 2 and 3.

**Warning**! Array in R starts from

__NOT__

**1**__(zero)!__

**0***Change Value*

__c.2.__Now, lets change one of the values stored in

__vector. As we do above, the second value (no.2) is the word__

**c***. Try to change it to*

**learn****love**, as in:

> wordlist[2] <- 'love'

Then, pick the number to show it has successfully changed by typing as follows:

> wordlist[2]

R will give you the result: [1] "love"

*Add New Value*

__c.3.__Type as follows:

> wordlist[4] <- 'badly'

This is the way if you need to add new value and store it in

**wordlist**variable. So, there are 4 values now;

**,**

*I**,*

**love***and*

**R-language***.*

**badly***Access more than one Value.*

__c.4.__If you want to access the stored variable and pick two or more value to show, then use

**Square Brackets**/ [ .......] where

__vector within it.__

**c**Example:

wordlist [ c (2,4) ]

Result: [1] "love" "badly"

*Access more than one value in a certain range.*

__c.5.__From the discussion above, we already have 4 values;

*I*,

*love*,

*R-language*,

*badly*. If we need to show more than one value

__in a range__, say,

*to*

**2***or*

**4**__through__

*love*__, then you can type as follows:__

*badly*> wordlist [2:4]

Result: [1] "love" "R-language" "badly"

*that the range value is inside square brackets!*

**Note***Add more than one value inside*

__c.6.____vector__

**c**If you want to add more than one value and store them inside the variable

*, then just type it and R will do that for you :p*

**wordlist**For example, we add three values at number 5,6 and 7.

wordlist[5:7]<-c('and','you','do')

Then, show it by typing as follows:

> wordlist [6]

Result: [1] "you"