# Index vectors

**R-exercises**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In the exercises below we cover the basics of index vectors. Before proceeding, first read section 2.7 of An Introduction to R, and the help pages for the `sum`

, and `which`

functions.

Answers to the exercises are available here.

**Exercise 1**

If `x `

, what will be the output for x[(c(2,3)]?

a. “ee”, “ff”

b. “ee”

c. “ff”

**Exercise 2**

If `x `

, what will be the third value in the index vector operation `x[c(2, 4, 4)]`

?

a. “uu”

b. NA

c. “kk”

**Exercise 3**

If ` x `

, what will be the fourth value in the index vector operation `x[-2]`

?

a. “aa”

b. “gg”

c. “bb”

**Exercise 4**

Let `a `

and `b `

, what will be the output for the R expression `max(a[b])`

?

**Exercise 5**

Let `a `

and `b `

, what will be the output for the R expression `sum(a[b])`

?

**Exercise 6**

Write an R expression that will return the sum value of 10 for the vector `x `

**Exercise 7**

If `x `

write an r expression that will return the output 1, 3, 5, 7.

**Exercise 8**

Consider the data frame `s `

. Write an R statement that will return the output 2, 4, 10, by using the variable `first`

as an index vector.

**Exercise 9**

What will be the output for the R expression `(c(FALSE, TRUE)) || (c(TRUE, TRUE))`

?

**Exercise 10**

Write an R expression that will return the positions of 3 and 7 in the vector `x `

.

**leave a comment**for the author, please follow the link and comment on their blog:

**R-exercises**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.