views:

94

answers:

1

Hi all,

Basically I got the problem solved, but I am trying to find a more elegant solution since the code gets a little bit hard to read. Here´s what I got:

mydf$size_class = ifelse(mydf$absolute_number <= 5,"1-5",ifelse(mydf$absolute_number > 6 &    
mydf$absolute_number <= 10,"6-10","x"))

Maybe I need rather some formatting help / hints, convention than a new code :) – those are also very welcome ;)

+4  A: 

Try the cut function:

R> x <- 1:10
R> cut(x, breaks = c(0, 5, 10), labels=c("1-5", "6-10"))
 [1] 1-5  1-5  1-5  1-5  1-5  6-10 6-10 6-10 6-10 6-10
Levels: 1-5 6-10
rcs
not bad actually :). i like that.
ran2