# >
Data structures
In-class coding
Make a sequence from 0 to 100 in steps of 10.
Create a repetition of “yes” and “no” with 10 instance of each, alternating between the two. Then make one with 10 “yes” and then 10 “no”.
# >
Add the argument n = 10
to head(mtcars)
. What does this do?
# >
Extra coding practice
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.
# >
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
.
# >