Search code examples
rmultiple-columnscreate-tablerepeatrep

Creating repeating set from another column in R


Using these dataset:

[A]
100
200
300

[B]
A
B
C

I would like to make this column:

[A]   [B]
100    A
100    B
100    C
200    A
200    B
200    C
300    A
300    B
300    C

I would like to use rep function in R, but it does not work. How do I create this column?


Solution

  • With rep() as follows

    data.frame(A=rep(c(100,200,300), c(3,3,3)),
                   B=rep(c("A", "B", "C"), 3))