Recall & Review
beginner
What does the
length() function do when applied to a vector in R?The
length() function returns the number of elements in the vector. It tells you how many items are inside.Click to reveal answer
beginner
How does the
sum() function work on a numeric vector in R?The
sum() function adds up all the numbers in the vector and gives you the total.Click to reveal answer
beginner
What is the purpose of the
mean() function in R?The
mean() function calculates the average value of the numbers in a numeric vector by adding them up and dividing by the count.Click to reveal answer
beginner
If you have a vector
c(2, 4, 6, 8), what will length(), sum(), and mean() return?length() returns 4 because there are 4 numbers.<br>sum() returns 20 because 2+4+6+8=20.<br>mean() returns 5 because 20 divided by 4 is 5.Click to reveal answer
intermediate
Can
sum() and mean() be used on non-numeric vectors?No,
sum() and mean() only work on numeric vectors. Using them on non-numeric vectors will cause an error.Click to reveal answer
What does
length(c(1, 3, 5, 7)) return?✗ Incorrect
length() counts how many elements are in the vector, which is 4.What is the result of
sum(c(10, 20, 30))?✗ Incorrect
sum() adds all numbers: 10 + 20 + 30 = 60.Which function calculates the average of numbers in a vector?
✗ Incorrect
mean() calculates the average value.What happens if you use
sum() on a character vector like c('a', 'b')?✗ Incorrect
sum() only works on numbers, so it gives an error on characters.If a vector has 5 elements, what will
length() return?✗ Incorrect
length() returns the count of elements, which is 5.Explain what the functions
length(), sum(), and mean() do when used on a numeric vector in R.Think about counting, adding, and averaging.
You got /3 concepts.
Describe a real-life example where you might use
length(), sum(), and mean() on a list of numbers.Imagine you have a list of test scores.
You got /4 concepts.