In R, Vector is a collection of same data type just like one Dimensional array in C.
we can create vector as follows
v=c()
or
v=c(1,2,3,4,5)
first statement is the creation of empty vector whereas second statement is the creation of the vector with some value.
to calculate length of vector we can use length function like
x=length(v)
To Access any element from vector, we can use index position, here index position starts from 1 (where as in c Array index position starts from 0)
i.e, if you want to access 4 from above vector, then you can write x=v[4]
To access all the element from the vector
x = c(1,3,4,7)
n = length(x)
for(i in 1:n)
{
print(x[i])
}
Thank You , Keep Learning
0 Comments:
Post a Comment
If you have any doubts . Please let me know.