Skip to content
Prev 32480 / 398502 Next

vectorizing data.frame()

Hello everybody.

I have a dozen or so vectors (of different lengths) which I want to
coalesce into a dataframe, as in the following toy example.

R> foo <- c(1,2,3)
R> bar <- c(7,8)
R> data.frame(name =c(rep("foo",length(foo)),rep("bar",length(bar))),
              value=c(foo,bar))

  name value
1   foo     1
2   foo     2
3   foo     3
4   bar     7
5   bar     8

Is there a better (vectorized) way?