- 2

friends... is sth wrong with this?

colors <- c("Red", "Green", "Blue", "Purple", "Black", "Yellow", "Orange", "Pink", "Brown", "White") print(colors[3])

18th Oct 2021, 7:21 PM
Tree
Tree - avatar
25 Respostas
+ 3
Tree Great so you have learnt many things 1 - in R language index starts from 1 not 0 2 - You have to read 1st line of the input means input[1] 3 - Don't write Hard Code value
18th Oct 2021, 9:03 PM
A͢J
A͢J - avatar
+ 3
Tree No that's not right. You have to do print(colors[n]) You have to pass user input n not hard code value ------And vector should be like this------ colors <- c("Red", "Green", "Blue", "Purple", "Black", "Yellow", "Orange", "Pink", "Brown", "White")
18th Oct 2021, 8:43 PM
A͢J
A͢J - avatar
+ 3
Tree Why did you change input[1] to input[3] You don't need to change that
18th Oct 2021, 8:49 PM
A͢J
A͢J - avatar
+ 3
Why input[3]? We need the 1st line of the input!
18th Oct 2021, 8:50 PM
Lisa
Lisa - avatar
+ 2
type your code in code playground & save then share the link here Tree
18th Oct 2021, 7:37 PM
Adithya Keshav T
Adithya Keshav T - avatar
+ 2
Tree you are getting the output Blue
18th Oct 2021, 7:43 PM
Adithya Keshav T
Adithya Keshav T - avatar
+ 2
Is it the task from the R course? Look closely at the task description: the index is a number we input. So it is not always 3 but any number a user types in
18th Oct 2021, 7:54 PM
Lisa
Lisa - avatar
+ 2
* Get input and store it in a variable * convert input to integer * use this number to index the vector
18th Oct 2021, 8:01 PM
Lisa
Lisa - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ Lisa Adithya Keshav T thank you all very much. :) it worked. :)
18th Oct 2021, 8:53 PM
Tree
Tree - avatar
+ 1
Purple Tree
18th Oct 2021, 7:24 PM
Adithya Keshav T
Adithya Keshav T - avatar
+ 1
"Blue" is to be printed
18th Oct 2021, 7:27 PM
Tree
Tree - avatar
+ 1
Then print(colors[2]) Tree
18th Oct 2021, 7:29 PM
Adithya Keshav T
Adithya Keshav T - avatar
+ 1
that is green
18th Oct 2021, 7:31 PM
Tree
Tree - avatar
+ 1
Tree 1 is red 2 is green 3 is blue & so on
18th Oct 2021, 7:33 PM
Adithya Keshav T
Adithya Keshav T - avatar
+ 1
when i print 3 the output is Blue but it does not accept. don't know why
18th Oct 2021, 7:35 PM
Tree
Tree - avatar
+ 1
Tree Adithya Keshav T In R language index start from 1 not 0 so colors[3] = Blue
18th Oct 2021, 8:32 PM
A͢J
A͢J - avatar
+ 1
You need to specify in the question that it's related to the R language.
19th Oct 2021, 8:44 PM
Sonic
Sonic - avatar
0
i know. there is a green checkmark but it doesn't give 10 xp
18th Oct 2021, 7:52 PM
Tree
Tree - avatar
0
yes it's R. it says "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. " A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟
18th Oct 2021, 7:59 PM
Tree
Tree - avatar