Data Frames
- 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
- Extract the first two columns and first two rows. HINT: Use the same
notation as matrices.
- Extract the second column using the column names. You can use
[ ]
or $
; use both the method in two different
answers.
- 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.
- 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
- 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.
- Extract the first column of the matrix contained in the list.