[R] aggregate by column names

Henrique Dallazuanna wwwhsd at gmail.com
Thu Feb 18 17:01:06 CET 2010


Try this:

xtabs(V5 ~ V1 + V6, data = DF)

On Thu, Feb 18, 2010 at 1:50 PM, Alfredo Alessandrini
<alfreale74 at gmail.com> wrote:
> Hi,
>
> I've this dataframe:
>
>                 V1     V5 V6
> 1   MOD13Q1_2000049 0.1723 A1
> 2   MOD13Q1_2000049 0.1824 B1
> 3   MOD13Q1_2000049 0.1824 C1
> 4   MOD13Q1_2000049 0.1774 A2
> 5   MOD13Q1_2000049 0.1953 B2
> 6   MOD13Q1_2000049 0.1824 C2
> 7   MOD13Q1_2000065 0.1921 A1
> 8   MOD13Q1_2000065 0.1938 B1
> 9   MOD13Q1_2000065 0.2009 C1
> 10  MOD13Q1_2000065 0.2035 A2
> 11  MOD13Q1_2000065 0.2157 B2
> 12  MOD13Q1_2000065 0.2157 C2
> 13  MOD13Q1_2000081 0.1997 A1
> 14  MOD13Q1_2000081 0.2060 B1
> 15  MOD13Q1_2000081 0.2140 C1
> 16  MOD13Q1_2000081 0.1997 A2
> 17  MOD13Q1_2000081 0.2099 B2
> 18  MOD13Q1_2000081 0.2099 C2
>
>
> Can I aggreate the data$V5 by the column "V6"?
>
> Like this:
>
>        A1      A2      B1      B2      C1      C2
> MOD13Q1_2000049 0.1723  0.1774  0.1824  0.1953  0.1824  0.1824
> MOD13Q1_2000065 0.1921  0.2035  0.1938  0.2157  0.2009  0.2157
> MOD13Q1_2000081 0.1997  0.1997  0.206   0.2099  0.214   0.2099
>
>
>
> Thanks,
>
> Alfredo
>
> ______________________________________________
> 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