Explain the concept of 'Vectors' in 'R' language

 Posted by Niladri.Biswas on 5/1/2013 | Category: Others Interview questions | Views: 1064 | Points: 40
Answer:

Vectors are one-dimensional arrays that can hold numeric data, character data, or logical data. The combine function c() is used to form the vector.
e.g.
a <- c(1, 2, 5, 3, 6, -2, 4)

b <- c("one", "two", "three")
c <- c(TRUE, TRUE, TRUE, FALSE, TRUE, FALSE)


Here, a is numeric vector, b is a character vector, and c is a logical vector.
The data in a vector must only be one type or mode (numeric, character, or logical). We can’t mix modes in the same vector.

We can refer to elements of a vector using a numeric vector of positions within brackets.For example, a[c(2, 4)] refers to the 2nd and 4th element of vector a.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response