[R-sig-Debian] aggregate() example fails]

Douglas Bates bates at stat.wisc.edu
Tue Mar 24 17:26:11 CET 2009


R, as installed from the 64-bit Ubuntu r-base-core package, doesn't
have a problem with example(aggregate).  All the examples are checked
on many different architectures before a version of R is released.  It
is unlikely that a version would get out with an error in an example
like this on a comparatively common architecture.

Why not use the prepared packages from the Ubuntu repository on CRAN
instead of compiling your own version?  See the instructions at
http://cran.r-project.org/bin/linux/ubuntu


R version 2.8.1 (2008-12-22)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> options(STERM='iESS', editor='emacsclient')
> sessionInfo()
R version 2.8.1 (2008-12-22)
x86_64-pc-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
> example(aggregate)

aggrgt> ## Compute the averages for the variables in 'state.x77', grouped
aggrgt> ## according to the region (Northeast, South, North Central, West) that
aggrgt> ## each state belongs to.
aggrgt> aggregate(state.x77, list(Region = state.region), mean)
         Region Population   Income Illiteracy Life Exp    Murder  HS Grad
1     Northeast   5495.111 4570.222   1.000000 71.26444  4.722222 53.96667
2         South   4208.125 4011.938   1.737500 69.70625 10.581250 44.34375
3 North Central   4803.000 4611.083   0.700000 71.76667  5.275000 54.51667
4          West   2915.308 4702.615   1.023077 71.23462  7.215385 62.00000
     Frost      Area
1 132.7778  18141.00
2  64.6250  54605.12
3 138.8333  62652.00
4 102.1538 134463.00

aggrgt> ## Compute the averages according to region and the occurrence of more
aggrgt> ## than 130 days of frost.
aggrgt> aggregate(state.x77,
aggrgt+           list(Region = state.region,
aggrgt+                Cold = state.x77[,"Frost"] > 130),
aggrgt+           mean)
         Region  Cold Population   Income Illiteracy Life Exp    Murder
1     Northeast FALSE  8802.8000 4780.400  1.1800000 71.12800  5.580000
2         South FALSE  4208.1250 4011.938  1.7375000 69.70625 10.581250
3 North Central FALSE  7233.8333 4633.333  0.7833333 70.95667  8.283333
4          West FALSE  4582.5714 4550.143  1.2571429 71.70000  6.828571
5     Northeast  TRUE  1360.5000 4307.500  0.7750000 71.43500  3.650000
6 North Central  TRUE  2372.1667 4588.833  0.6166667 72.57667  2.266667
7          West  TRUE   970.1667 4880.500  0.7500000 70.69167  7.666667
   HS Grad    Frost      Area
1 52.06000 110.6000  21838.60
2 44.34375  64.6250  54605.12
3 53.36667 120.0000  56736.50
4 60.11429  51.0000  91863.71
5 56.35000 160.5000  13519.00
6 55.66667 157.6667  68567.50
7 64.20000 161.8333 184162.17

aggrgt> ## (Note that no state in 'South' is THAT cold.)
aggrgt>
aggrgt> ## example with character variables and NAs
aggrgt> testDF <- data.frame(v1 = c(1,3,5,7,8,3,5,NA,4,5,7,9),
aggrgt+                      v2 = c(11,33,55,77,88,33,55,NA,44,55,77,99) )

aggrgt> by1 <- c("red","blue",1,2,NA,"big",1,2,"red",1,NA,12)

aggrgt> by2 <- c("wet","dry",99,95,NA,"damp",95,99,"red",99,NA,NA)

aggrgt> aggregate(x = testDF, by = list(by1, by2), FUN = "mean")
  Group.1 Group.2 v1 v2
1       1      95  5 55
2       2      95  7 77
3       1      99  5 55
4       2      99 NA NA
5     big    damp  3 33
6    blue     dry  3 33
7     red     red  4 44
8     red     wet  1 11

aggrgt> # and if you want to treat NAs as a group
aggrgt> fby1 <- factor(by1, exclude = "")

aggrgt> fby2 <- factor(by2, exclude = "")

aggrgt> aggregate(x = testDF, by = list(fby1, fby2), FUN = "mean")
   Group.1 Group.2  v1   v2
1        1      95 5.0 55.0
2        2      95 7.0 77.0
3        1      99 5.0 55.0
4        2      99  NA   NA
5      big    damp 3.0 33.0
6     blue     dry 3.0 33.0
7      red     red 4.0 44.0
8      red     wet 1.0 11.0
9       12    <NA> 9.0 99.0
10    <NA>    <NA> 7.5 82.5

aggrgt> ## Compute the average annual approval ratings for American presidents.
aggrgt> aggregate(presidents, nfrequency = 1, FUN = mean)
Time Series:
Start = 1945
End = 1974
Frequency = 1
 [1]    NA 47.00 51.00    NA 58.50 41.75 28.75    NA 67.00 65.00 72.75 72.25
[13] 65.25 52.25 61.50 62.75 76.00 71.50 64.75 72.75 66.50 52.25 45.00 41.00
[25] 61.25 58.00 50.50    NA 44.75 25.25

aggrgt> ## Give the summer less weight.
aggrgt> aggregate(presidents, nfrequency = 1,
aggrgt+           FUN = weighted.mean, w = c(1, 1, 0.5, 1))
Time Series:
Start = 1945
End = 1974
Frequency = 1
 [1]       NA 47.57143 50.57143       NA 58.71429 41.14286 28.28571       NA
 [9] 65.85714 64.14286 71.85714 73.00000 65.57143 52.85714 61.57143 63.00000
[17] 76.71429 72.85714 65.14286 73.28571 66.14286 51.71429 46.00000 41.85714
[25] 60.71429 57.57143 50.00000       NA 45.42857 25.42857


On Tue, Mar 24, 2009 at 8:39 AM, Michael Rutter <mar36 at psu.edu> wrote:
> Kenneth,
>
> example(aggregate) works fine on the amd64 ubuntu packages on CRAN.  You are
> running a slightly newer version (an alpha or beta, I think), which may be a
> problem.  If I get a chance in the next couple of days, I will try the new
> beta to see if example(aggregate) still works.  My suggestion would be to
> use the packages on CRAN.  Is there are reason why those are not sufficient?
>
> Michael
>
> Kenneth Roy Cabrera Torres wrote:
>>
>> Hi R users and developers on debian platforms.
>>
>> I compile the R version 2.8.1 Patched (2009-03-18 r48193) on my UBUNTU
>> linux distribution.
>>
>> But when I ask for the aggregate example it fails.
>>
>> What am I missing?
>>
>>
>> example(aggregate)
>>
>> aggrgt> ## Compute the averages for the variables in 'state.x77',grouped
>> aggrgt> ## according to the region (Northeast, South, North Central,West)
>> that
>> aggrgt> ## each state belongs to.
>> aggrgt> aggregate(state.x77, list(Region = state.region), mean)
>> Error en FUN(X[[1L]], ...) :  elemento 1 esta vacio;
>>  la parte de la lista de argumentos  'is.list' ha sido evaluada: (INDEX)
>>
>> I discovery this behavior when I try to use old scripts that uses
>> the aggregate() function, but now it fails on my old scripts.
>>
>> Thank you for your help.
>>
>> Kenneth
>> PD: R.Version() returns:
>> $platform
>> [1] "x86_64-unknown-linux-gnu"
>> $arch
>> [1] "x86_64"
>> $os
>> [1] "linux-gnu"
>> $syste
>> [1] "x86_64, linux-gnu"
>> $status
>> [1] "Patched"
>> $major
>> [1] "2"
>> $minor
>> [1] "8.1"
>> $year
>> [1] "2009"
>> $month
>> [1] "03"
>> $day
>> [1] "18"
>> $`svn rev`
>> [1] "48193"
>> $language
>> [1] "R"
>> $version.string
>> [1] "R version 2.8.1 Patched (2009-03-18 r48193)"
>>
>> _______________________________________________
>> R-SIG-Debian mailing list
>> R-SIG-Debian at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-debian
>
> --
> Dr. Michael A. Rutter
> School of Science
> Penn State Erie, The Behrend College
> Station Road
> Erie, PA 16563
> http://math.bd.psu.edu/faculty/rutter
>
> _______________________________________________
> R-SIG-Debian mailing list
> R-SIG-Debian at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-debian
>



More information about the R-SIG-Debian mailing list