Data structures

Author

Jeffrey R. Stevens

Published

February 5, 2025

Vectors

Create a vector called dog_names with the values Bella, Daisy, and Max.

# >

Create a vector called sex with the values Female, Male, and Male.

# >

Use the index operator to print to console only Daisy and Max from dog_names.

# >

Replace the Daisy entry with Luna and print dog_names to console.

# >

Test whether the name Sophie is contained in the vector dog_names.

# >

Lists

Copy/paste and run this code: (mylist <- list(a = 1:4, b = c(4, 3, 8, 5), c = LETTERS[10:15], d = c("yes", "yes")))

# >

Check the data types for each list element individually.

# >

Check the data types for each list element with one command.

# >

Combine list elements a and b into a single vector.

# >

Data frames

Create a data frame called mydf with three columns: x, y, and z and five rows. For x assign any five numbers, for y assign any five character strings, and for z assign any five logical values.

# >

Create a data frame called dogs that combines the dog_names and sex vectors and print to console.

# >

Print to console just Luna’s row.

# >

Print to console the number of rows in dogs.

# >