How to do it...

Perform the following steps to manipulate the data with R.

Subset the data using the bracelet notation:

  1. Load the dataset iris into the R session:
        > data(iris)  
  1. To select values, you may use a bracket notation that designates the indices of the dataset. The first index is for the rows and the second for the columns:
        > iris[1,"Sepal.Length"]
        Output:
    
        [1] 5.1  
  1. You can also select multiple columns using c():
        > Sepal.iris = iris[, c("Sepal.Length", "Sepal.Width")]  
  1. You can then use str() to summarize and display the internal structure of Sepal.iris:
 > str(Sepal.iris) Output: 'data.frame': 150 obs. of 2 variables: $ Sepal.Length: num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width : num 3.5 3 3.2 3.1 3.6 3.9 3.4 ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.