Data Frames

  1. Make a data frame with 3 columns and 5 rows in which:
  • The first column contains the sequence of numbers from 1 to 5
  • The second column contains a character vector
  • The third column contains a logical vector

  1. Extract the first two columns and first two rows. HINT: Use the same notation as matrices.

  1. Extract the second column using the column names. You can use [ ] or $; use both the method in two different answers.

  1. Extract rows where the 1st column is larger than 3. HINT: You can get a logical vector using the > operator, and logical vectors can be used in [ ] when subsetting.

  1. Convert the data frame to the matrix format. HINT: Use as.matrix(). Observe what happens to numeric and logical values in the data frame.

Lists

  1. Make a list using the list() function. Your list should have 4 elements:
  • two vectors (a logical one and a numeric one)
  • a matrix
  • a data frame.

  1. Extract the first column of the matrix contained in the list.