creating factors in R with differing number of replicates -
the following command
region <- gl(6,2,24, label=c("ag", "cb", "cx", "ec", "hp", "mb"))
creates factor in following way
structure(c(1l, 1l, 2l, 2l, 2l, 3l, 4l, 4l, 5l, 5l, 6l, 6l, 1l, 1l, 2l, 2l, 3l, 3l, 4l, 4l, 5l, 5l, 6l, 6l), .label = c("ag", "cb", "cx", "ec", "hp", "mb"), class = "factor")
but when try create differing number of replicates goes wrong. instance when ag , cb 3 replicates each , need this
structure(c(1l, 1l,1l, 2l, 2l, 2l, 2l, 3l, 4l, 4l, 5l, 5l, 6l, 6l, 1l, 1l, 2l, 2l, 3l, 3l, 4l, 4l, 5l, 5l, 6l, 6l), .label = c("ag", "cb", "cx", "ec", "hp", "mb"), class = "factor")
how write command
region <- gl(6,2,24, label=c("ag", "cb", "cx", "ec", "hp", "mb")) now?
you need in exact order? if not, work:
factor(rep(c('ag', 'cb', 'cx', 'ex', 'hp', 'mb'), times=c(5, 6, 3, 4, 4, 4)))
if order important, adapt code should easy.
Comments
Post a Comment