Page 223 - Data Science class 11
P. 223
Example
Enter the following code snippet:
r <- c(‘orange’,’mango’,16,FALSE)
print(r)
p <- c(1:7,10.5,’NEXT’)
print(p)
The following result is produced:
6.7.3 accessing Vector elements
There are several methods of accessing vector elements:
a. using position
b. using logical indexing
c. using negative indexing
d. using 0/1 indexing
a. using position
You can access the data using the position of each data element in the sequence. Here the position numbering starts
with 1.
Example
Enter the following code snippet:
# Accessing vector elements using position
t <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul")
u <- t[c(1,3,6)]
print(u)
Observe here the types of brackets in the third line of the above program snippet.
The following result is produced:
Programming with R 221

