Index in vector


In the index in vector topic, the lesson said that: “we can create a new vector of the desired indices and use this new vector of indices to extract the desired values from the original vector”
Ex: exam_grades[c(1,3,7)]

May I use: exam_grades[1,3,7]

Thank you

Hello @hongchi0502

It is good to include the link to the mission.

Please can you restate your question?

1 Like

NO!!, this will result to an incorrect number of dimensions error

Error in exam_grades[1, 3, 7] : incorrect number of dimensions

c(1,3,7) is a vector, you can use a vector to select vector elements of another vector if the vector elements are not next to each other as in this vector it will select the first, third and the seventh element in the exam_grades vector.