Re: [R] Vector Assignments

2003-12-03 Thread Gabor Grothendieck
If you were using the colours in a model matrix using a factor would be best but since your case is plotting using characters is best. Date: 03 Dec 2003 08:26:05 -0500 From: Arend P. van der Veen <[EMAIL PROTECTED]> To: R HELP <[EMAIL PROTECTED]> Subject: Re: [R] Vector

Re: [R] Vector Assignments

2003-12-03 Thread Arend P. van der Veen
a good job for a factor: > > colours <- c("red", "blue", "green","black") > cut(x, c(-Inf,250,500,700,Inf),right=F,lab=colours) > > > > --- > Date: Mon, 1 Dec 2003 23:47:39 -0500 (EST) > From: Gabor Grothendieck <[EM

Re: [R] Vector Assignments

2003-12-01 Thread Gabor Grothendieck
f),right=F,lab=colours) --- Date: Mon, 1 Dec 2003 23:47:39 -0500 (EST) From: Gabor Grothendieck <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Subject: Re: [R] Vector Assignments Just some small refinements/corrections:

Re: [R] Vector Assignments

2003-12-01 Thread Gabor Grothendieck
d P. van der Veen <[EMAIL PROTECTED]> Cc: R HELP <[EMAIL PROTECTED]> Subject: Re: [R] Vector Assignments One way would be to create a vector of colours and then cut() to index the vector: colours <- c("red", "blue", "green","back") colours[c

Re: [R] Vector Assignments

2003-12-01 Thread Thomas W Blackwell
Arend - Here is a sequence of commands which will do it. These first build a vector of (4+1) cutpoints, then cut() returns a factor whose labels are the colors and codes are determined by x. Last, as.character() turns the factor into the character vector which you ask for. Or, perhaps the fa

Re: [R] Vector Assignments

2003-12-01 Thread Hadley Wickham
One way would be to create a vector of colours and then cut() to index the vector: colours <- c("red", "blue", "green","back") colours[cut(x, c(min(x),250,500,700,max(x)),lab=F)] Hadley Arend P. van der Veen wrote: Hi, I have simple R question. I have a vector x that contains real numbers.

Re: [R] Vector Assignments

2003-12-01 Thread Spencer Graves
One way is to use "ifelse": x <- seq(100, 1000, by=100) x.col <- ifelse(x < 250, "red", ifelse(x<500, "blue", ifelse(x<750, "green", "black"))) data.frame(x, x.col) x x.col 1 100 red 2 200 red 3 300 blue 4 400 blue 5 500 green 6 600 green 7 700 green 8 800 black

[R] Vector Assignments

2003-12-01 Thread Arend P. van der Veen
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