Skip to content
Prev 307621 / 398506 Next

Converting factors to bounded random numerical data

You need to include how many random numbers you want to create; you
are asking for only 1, that is why they are are the same.  You
probably want something like:

a$Z<-ifelse(a$Z=="L"
    ,sample(1:4, nrow(a), TRUE)
    ,ifelse(a$Z=="M"
        ,sample(5:9, nrow(a), TRUE)
        ,ifelse(a$Z=="U"
            ,sample(10:12, nrow(a), TRUE)
            , -42  # you had a character which would have converted
everything to character
            )
        )
    )
On Wed, Oct 10, 2012 at 8:36 PM, KoopaTrooper <ncooper1 at tulane.edu> wrote: