[R] Using combn

Patrick Hausmann patrick.hausmann at uni-bremen.de
Mon Jan 10 17:34:50 CET 2011


Dear list,

I want to apply the "table" function to every pair of variables in df 
and the return should be a list.

setwd(123)
asd <- data.frame(a1=sample(1:4, 20, replace=TRUE),
                   a2=sample(1:4, 20, replace=TRUE),
                   a3=sample(1:4, 20, replace=TRUE),
                   a4=sample(1:4, 20, replace=TRUE))

with(asd, table(a1, a2))
with(asd, table(a1, a3))
with(asd, table(a1, a4))
...

I'm sure there is a solution using "combn" - but I don't get it...

combn(colnames(asd), 2)
...

Thanks for any help!
Patrick



More information about the R-help mailing list