Try this:

combn(colnames(asd), 2, function(x)table(asd[x]))

On Mon, Jan 10, 2011 at 2:34 PM, Patrick Hausmann <
patrick.hausmann@uni-bremen.de> wrote:

> 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
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

