+ 2

Problem with R code (unit Vector).

So. here is the task. You are given a vector that contains color names. You need to take a number as input, and output the color name at that index. Here is my solution. colors <- c("Red", "Green", "Blue", "Purple", "Black", "Yellow", "Orange", "Pink", "Brown", "White") var <- readline() var <- as.integer(var) print(colors[var]) Could you please explain to me what is wrong with it?

1st Jul 2024, 9:02 PM
Olga
2 ответов
+ 3
in the examples, it shows that input should be gotten like this: input <- readLines('stdin') (not readline())
2nd Jul 2024, 1:13 AM
Lisa
Lisa - avatar
0
Lisa, Thank you! I've followed this (https://www.geeksforgeeks.org/taking-input-from-user-in-r-programming/), as I could find an example in the unit.
2nd Jul 2024, 6:56 AM
Olga