< Back
Page 8 of 8

This chapter is from the book

## Activities

Create a “named” list containing a numeric vector with 10 values (called X) and a character vector with 10 values (called Y) and a sequence of values from 1 to 10 (called Z). Use this list:

- Print the number of elements and the element names.
- Select the X element.
- Select the Y element.
- Select values of the X element that are greater than the median of X.
- Select values of the Y element where the corresponding X element is greater than the median of X.

Adapt your code to instead create a data frame containing two columns (X = a numeric vector with 10 elements, Y = a character column containing 10 elements, Z = integers 1 to 10). Use this structure:

- Print the number of columns and the column names.
- Select the X column.
- Select the Y column.
- Select values of the X column that are greater than the median of X.
- Select values of the Y column where the corresponding X value is greater than the median of X.

Further subset the data in the data frame created in the last exercise as follows:

- Select all rows of the data where Z is greater than 5.
- Select all rows of the data where Z is greater than 3 and X is greater than the median of X.
- Select just the X and Z columns from the data where Z is greater than 5.

Print the built-in

`mtcars`data frame. Look at the help file for`mtcars`to understand the origin of the data. Use this data frame:- Print only the first five rows.
- Print the last five rows.
- How many rows and columns does the data have?
- Look at the data in the RStudio data viewer (if you are using RStudio).
- Print the
`mpg`column of the data. - Print the
`mpg`column of the data where the corresponding`cyl`column is 6. - Print all rows of the data where
`cyl`is 6. - Print all rows of the data where
`mpg`is greater than 25, but only for the`mpg`and`cyl`columns. - Create a scatter-plot matrix of your data.
- Create a scatter-plot matrix of your data, but only using the first six columns of the data.

< Back
Page 8 of 8