Complete the code to create a vector of numbers from 1 to 5.
numbers <- [1](1, 5)
c creates a vector but does not generate a sequence automatically.rep repeats values instead of creating a sequence.The seq function generates a sequence of numbers from the first to the second argument.
Complete the code to calculate the mean of the vector 'values'.
average <- [1](values)sum returns the total, not the average.length returns the count of elements, not the average.The mean function calculates the average value of a numeric vector.
Fix the error in the code to subset the vector 'data' for values greater than 10.
subset <- data[data [1] 10]
== selects only values exactly equal to 10.<= or < selects smaller or equal values.The operator > selects elements greater than 10 from the vector.
Fill both blanks to create a named list with elements 'a' and 'b'.
my_list <- list([1] = 1, [2] = 2)
In R, you name list elements by using name = value. Here, 'a' and 'b' are the names.
Fill all three blanks to create a data frame with columns 'name' and 'age' and filter rows where age is greater than 20.
df <- data.frame([1] = c("Alice", "Bob"), [2] = c(25, 19)) adults <- df[df$[3] > 20, ]
The data frame columns are named 'name' and 'age'. To filter rows where age is greater than 20, use df$age > 20.