tags:

views:

91

answers:

2

I have a data.frame:

df<-data.frame(a=c("x","x","y","y"),b=c(1,2,3,4))

> df
      a b
    1 x 1
    2 x 2
    3 y 3
    4 y 4

What's the easiest way to print out each pair of values as a list of strings like this:

"x1", "x2", "y1", "y2"

+6  A: 
apply(df, 1, paste, collapse="")
Shane
+5  A: 
Marek
I doubt the speed will be noticeably different unless you have millons of rows.
hadley
@hadley My solution is vectorized, what implies better performance.
Marek