0
0
R Programmingprogramming~10 mins

Useful vector functions (length, sum, mean) in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find the number of elements in the vector v.

R Programming
len <- [1](v)
Drag options to blanks, or click blank then click option'
Amean
Blength
Csum
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of length() to count elements.
Using mean() which calculates average, not count.
2fill in blank
medium

Complete the code to calculate the total sum of the vector v.

R Programming
total <- [1](v)
Drag options to blanks, or click blank then click option'
Alength
Bmean
Ccount
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() which counts elements, not sums them.
Using mean() which calculates average.
3fill in blank
hard

Fix the error in the code to calculate the average of vector v.

R Programming
avg <- [1](v)
Drag options to blanks, or click blank then click option'
Amean
Blength
Csum
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() which adds numbers but does not average.
Using length() which counts elements.
4fill in blank
hard

Fill both blanks to create a vector with word lengths greater than 3.

R Programming
lengths <- [1](words[[2](words) > 3])
Drag options to blanks, or click blank then click option'
Anchar
Blength
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() which counts elements in a vector, not characters in a string.
Using sum() which adds numbers, not counts characters.
5fill in blank
hard

Fill all three blanks to create uppercase words with character count greater than 4.

R Programming
result <- [1](words[[2](words) [3] 4])
Drag options to blanks, or click blank then click option'
Atoupper
Bnchar
C>
Dtolower
Attempts:
3 left
💡 Hint
Common Mistakes
Using tolower() instead of toupper() for uppercase conversion.
Using length() instead of nchar() for character count.