Create a list of 5 named elements, access each element, and print its type.
MediumProblem Statement
Create a list of 5 named elements, access each element, and print its type.
Sample Input
List: Name: "John" Age: 30 Scores: c(85, 90, 75) Passed: TRUE Address: "123 Main St"
Sample Output
[1] "John" [1] "Type: character" [1] 30 [1] "Type: numeric" [1] 85 90 75 [1] "Type: numeric" [1] TRUE [1] "Type: logical" [1] "123 Main St" [1] "Type: character"
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
# Predefined structure
my_list <- # Create the list
for (item in names(my_list)) {
print(my_list[[item]])
print(paste("Type:", class(my_list[[item]])))
}
Input
List: Name: "John" Age: 30 Scores: c(85, 90, 75) Passed: TRUE Address: "123 Main St"
Expected Output
[1] "John" [1] "Type: character" [1] 30 [1] "Type: numeric" [1] 85 90 75 [1] "Type: numeric" [1] TRUE [1] "Type: logical" [1] "123 Main St" [1] "Type: character"