0
0
R Programmingprogramming~10 mins

Character (string) type 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 create a character string variable named greeting with the value "Hello".

R Programming
greeting <- [1]
Drag options to blanks, or click blank then click option'
A"Hello"
BHello
C'Hello'
DHello()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the string
Using a function call instead of a string
2fill in blank
medium

Complete the code to find the number of characters in the string stored in word.

R Programming
length <- [1](word)
Drag options to blanks, or click blank then click option'
Acount
Bsize
Clength
Dnchar
Attempts:
3 left
💡 Hint
Common Mistakes
Using length() which counts elements in a vector, not characters in a string
Using undefined functions like count() or size()
3fill in blank
hard

Fix the error in the code to concatenate two strings with a space between them.

R Programming
full_name <- paste(first_name, [1], last_name)
Drag options to blanks, or click blank then click option'
A""
B' '
C'_'
Dspace
Attempts:
3 left
💡 Hint
Common Mistakes
Using empty quotes which join strings without space
Using an undefined variable like space
4fill in blank
hard

Fill both blanks to create a named vector with words as names and their lengths as values.

R Programming
word_lengths <- c([1] = nchar([2]))
Drag options to blanks, or click blank then click option'
Aword
Bwords
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing singular and plural variable names
Using undefined variables
5fill in blank
hard

Fill all three blanks to create a named vector of uppercase words with their lengths greater than 3.

R Programming
result <- c([1] = [2](word), nchar(word)[nchar(word) [3] 3])
Drag options to blanks, or click blank then click option'
Aword
Btoupper
C>
Dtolower
Attempts:
3 left
💡 Hint
Common Mistakes
Using tolower() instead of toupper()
Using wrong comparison operators like < or ==