[R] Permutations of variables in a dataframe

Henrique Dallazuanna wwwhsd at gmail.com
Mon Jan 14 14:39:59 CET 2008


If I understand your question use apply

?apply

On 14/01/2008, Serguei Kaniovski <Serguei.Kaniovski at wifo.ac.at> wrote:
> Hallo All,
>
> I would like to apply a function to all permutations of variables in a
> dataframe (except the first). What is the best way to achieve this?
>
> I produce the permutations using:
>
> nvar <- ncol(dat) - 1
> perms <- as.matrix( expand.grid(rep( list(1:0) , nvar ))[ , nvar:1] )
>
> Thanks in advance
> Serguei
>
> Test-dataframe, comma-delimited:
>
> code,wav,w,area,gdp,def,pop,coast,milspend,agr
> aut,5,10,83.87,26.39,-1.29,8.07,0,0.72,1.81
> bel,1,12,30.53,24.87,-0.28,10.29,0.07,1.29,1.09
> bul,7,10,110.91,2.14,1.22,8.03,0.35,1.46,10.88
> cyp,6,4,9.25,14.65,-3.26,0.7,0.65,2.11,3.2
> cze,6,12,78.87,6.88,-4.44,10.26,0,2,3.19
> dnk,2,7,43.09,32.75,2.05,5.34,7.31,1.53,1.98
> est,6,4,45.23,5.15,0.82,1.38,3.79,1.58,3.91
> fin,5,7,338.15,25.5,3.52,5.18,1.25,1.33,2.87
> fra,1,29,547.03,23.99,-2.63,61.05,3.43,2.61,2.39
>
> ______________________________________________
> R-help at 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




More information about the R-help mailing list