Q:

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 a factor in the 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 I try to create it for a differing number of replicates it goes wrong. For instance
when ag and cb are three replicates each and I would need something like 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 to write the command
       region <- gl(6,2,24, label=c("ag", "cb", "cx", "ec", "hp", "mb")) now?

A:

You need in that exact order? If not, this will work:
factor(rep(c('ag', 'cb', 'cx', 'ex', 'hp', 'mb'), times=c(5, 6, 3, 4, 4, 4)))

If the order is important, adapt the code should be easy.

