Question: In this exercise, you will practice vector subsetting. First run the following lines of code to create a vector x : x - seq (

In this exercise, you will practice vector subsetting.
First run the following lines of code to create a vector x :
x-seq(11,20,1) # search help to find out what seq() does.
names (x)- letters [1:10] # "letters" is an alphabet vector defined by R
x
a b c d e
11,12,13,14,15,16,17,18,19,20
Note that x is a vector of values from 11 to 20, and cach element is named by a letter in the alphabet.
R gives you the flexibility to subset a vector in multiple ways. Use each of the following ways to subset x to generate a vector of 3 values 17,18,19 :
a. Subset x by elements indices using the ) function.
b. Subset x using the colon operator for vector slicing.
Subset x with a logical index vector.
d. Subset x using the names of the corresponding elements.
e. Remember negative index can be used to delete an element from the vector? Use an index vector of negative values to subset x.
 In this exercise, you will practice vector subsetting. First run the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!