Generate double entry table with different data

I am using R-exams and I want to generate a double entry table, but each time with a different set of values (I propose 5 different ones: data1,data2,data3,data4,data5), but it does not work, neither with a counter, nor with "sample".

How could I do it? Thanks

datos1 = c(0 , 2 , 4 , 2, 4 , 8, 13, 6, 12)
datos2 = c(11 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos3 = c(12 , 2 , 14 , 2, 4 , 28, 3, 6, 12)
datos4 = c(13 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos5 = c(1 , 2 , 4 , 22, 4 , 8, 3, 6, 12)

w9 <- sample(c(datos1, datos2, datos3, datos4, datos5),1)

tabla = cbind (expand.grid (list (Y = c ("3","5","6") ,
X = c ("6","8","9"))), count = w9)
ftable (xtabs(count ∼ Y + X, tabla ))

Please indicate more clearly what you to achieve.
At what precise point are you getting an error?

Are you expecting that we find out what your problem is?

``````datos1 = c(0 , 2 , 4 , 2, 4 , 8, 13, 6, 12)
datos2 = c(11 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos3 = c(12 , 2 , 14 , 2, 4 , 28, 3, 6, 12)
datos4 = c(13 , 2 , 4 , 2, 4 , 8, 3, 6, 12)
datos5 = c(1 , 2 , 4 , 22, 4 , 8, 3, 6, 12)

w9 <- unlist(sample(list(datos1, datos2, datos3, datos4, datos5),1))

tabla = cbind (expand.grid (list (Y = c (3,5,6) ,
X = c (6,8,9))), count = w9)

ftable(xtabs(count ∼ Y + X, tabla))
``````

?
though I'm not entirely clear on what you are doing

If w9 is for example datos5, the output is for rows 1 22 3, 2 4 6 and 4 8 12. I want that from a set of 5 possible vectors, randomly choose a group (either data1, data2 or....data5). I don't want to concretely put a group. When I set it to randomly choose one of the groups the output is a row matrix with all 1 or 2 or 3....., i.e. 1 1 1 1, 1 1 1 1, 1 1 1 1, which is not correct, according to the values of the vectors.

According to my understanding of your question the solution of @nirgrahamuk does what you want.
Apparently not.