This is why your code is wrong and what it does:
colourName<-c("red", "green", "blue", "yellow", "white", "black") data <- c(1,2,3,4,5,6)
which sets two variables as vectors with these values.
myFunction <- function(colour){
which begins to define a new function with one parameter, colour .
colourName = data
which creates a new new variable called colourName , (the single = sign matches the <- sign) and gives the value data . This colourName variable is visible only inside the function. So now you have the variable colourName in the function whose value is c(1,2,3,4,5,6) , since its copy of data is outside the function.
return(colour) }
this returns the colour value as a result of the function. Since this is the same as the parameter in myFunction <- function(colour){ and you have not changed the colour variable, you will simply return what you put!
myFunction("red")
This calls the function by setting the colour argument to "red" . Now go through the function code and you will see that it will print [1] "red" - a vector identical to the input.
I know that this does not completely answer your question about how to get the number for the color you need, but you obviously do not understand a lot of the basics of programming, so I hope this helps.