[R] Vector Assignments

Arend P. van der Veen apv at capital.net
Tue Dec 2 02:19:54 CET 2003


Hi,

I have simple R question.  

I have a vector x that contains real numbers.  I would like to create
another vector col that is the same length of x such that:

if x[i] < 250 then col[i] = "red"
else if x[i] < 500 then col[i] = "blue"
else if x[i] < 750 then col[i] = "green"
else col[i] = "black" for all i

I am convinced that there is probably a very efficient way to do this in
R but I am not able to figure it out.  Any help would be greatly
appreciated.

Thanks in advance,
Arend van der Veen




More information about the R-help mailing list