Perform the following steps to manipulate the data with R.
Subset the data using the bracelet notation:
- Load the dataset iris into the R session:
> data(iris)
- 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
- You can also select multiple columns using c():
> Sepal.iris = iris[, c("Sepal.Length", "Sepal.Width")]
- 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 ...