[R] subset

Phil Spector spector at stat.berkeley.edu
Wed Dec 15 20:27:00 CET 2010


Silvano -
     If you always have exactly one med1, one med2, and one med3
for each combination of Grupos, Dias, and Rato, you can use

> aggregate(Esp.Inter.Trac~Grupos+Dias+ Rato,mean,data=x)
    Grupos Dias Rato Esp.Inter.Trac
1       C    3    1      100.55667
2     GFC    3    1       87.62333
3       C    3    2       80.37000
4     GFC    3    2      101.33000
5       C    3    3       66.97333
6     GFC    3    3      101.52667
7       C    3    4       84.84000
8     GFC    3    4      103.97333
9       C    3    5       76.99333
10    GFC    3    5      121.67000
11      C    3    6       70.78333
12    GFC    3    6       91.41000

If there are multiples of any of med1, med2, or med3 within
any of the combinations, it would be a little trickier:

> one = aggregate(Esp.Inter.Trac~Grupos+Dias+Rato+blocos,mean,data=x)
> two = aggregate(Esp.Inter.Trac~Grupos+Dias+Rato,mean,data=one)

That would still assume there was at least one value for each of
med1, med2, and med3 for each combination.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Thu, 16 Dec 2010, Silvano wrote:

> Hi,
>
> I have a file, like below, and I want create a new data.frame with variables:
> Grupos Dias Rato Esp.Inter.Trac,   but Esp.Inter.Trac will be the mean of
> med1 med2 and med3 for each Rato.
>
> How can I do this?
>
>
> Grupos  Dias Rato blocos Esp.Inter.Trac
>  GFC     3    1   med1          85.99
>  GFC     3    2   med1         112.78
>  GFC     3    3   med1         105.43
>  GFC     3    4   med1          86.18
>  GFC     3    5   med1         135.66
>  GFC     3    6   med1          76.25
>  GFC     3    1   med2          91.08
>  GFC     3    2   med2         100.57
>  GFC     3    3   med2         131.79
>  GFC     3    4   med2         138.46
>  GFC     3    5   med2         129.78
>  GFC     3    6   med2         107.92
>  GFC     3    1   med3          85.80
>  GFC     3    2   med3          90.64
>  GFC     3    3   med3          67.36
>  GFC     3    4   med3          87.28
>  GFC     3    5   med3          99.57
>  GFC     3    6   med3          90.06
>    C     3    1   med1          81.19
>    C     3    2   med1          94.74
>    C     3    3   med1          49.18
>    C     3    4   med1         105.76
>    C     3    5   med1          82.71
>    C     3    6   med1          80.10
>    C     3    1   med2         121.30
>    C     3    2   med2          82.77
>    C     3    3   med2          99.57
>    C     3    4   med2          73.66
>    C     3    5   med2          72.89
>    C     3    6   med2          76.47
>    C     3    1   med3          99.18
>    C     3    2   med3          63.60
>    C     3    3   med3          52.17
>    C     3    4   med3          75.10
>    C     3    5   med3          75.38
>    C     3    6   med3          55.78
>
> --------------------------------------
> Silvano Cesar da Costa
> Departamento de Estatística
> Universidade Estadual de Londrina
> Fone: 3371-4346
>
> ______________________________________________
> 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.
>


More information about the R-help mailing list