[R] vectorizing data.frame()

Robin Hankin r.hankin at auckland.ac.nz
Mon May 26 06:50:20 CEST 2003


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?


-- 

Robin Hankin, Lecturer,
School of Geography and Environmental Science
Tamaki Campus
Private Bag 92019 Auckland
New Zealand

r.hankin_AT_auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042




More information about the R-help mailing list