Skip to content
Prev 325745 / 398503 Next

How to define desired numbers to a vector based on the present numbers

Hello,

I'm not sure I understand. You want to attribute a color number 1:7 to 
each element of your vector? Maybe the following will do.


x <- scan(text = "
43 43 43 43  0 39 13 39 50 39 39 23 23 32  0 13 32 23 32 23  0 13 13  0
")

cols <- rep(1:7, rle(x[order(x)])$lengths)[order(order(x))]
plot(x, col = cols)


Hope this helps,

Rui Barradas

Em 21-06-2013 16:13, Suparna Mitra escreveu: