+ 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?
2 Antworten
+ 3
in the examples, it shows that input should be gotten like this:
input <- readLines('stdin')
(not readline())
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.