[R] Confused in simplest-possible function

About this list Date view Thread view Subject view Author view Attachment view

From: Ajay Shah (ajayshah@mayin.org)
Date: Mon 01 Mar 2004 - 04:14:21 EST


Message-id: <20040229171421.GA25919@igidr.ac.in>

I wrote the following code:

  ---------------------------------------------------------------------------
  oneindex <- function(x) {
        summary(x)
  }

  A <- read.table("try.data",
                  col.names=c("date", "lNifty"))
  summary(A)
  oneindex(A$lNifty)
  ---------------------------------------------------------------------------

where I read in data, make a summary directly, and then call a
function `oneindex' which merely makes a summary.

I'm puzzled because the two summaries disagree :

> oneindex <- function(x) {
+ summary(x)
+ }
>
> A <- read.table("try.data",
+ col.names=c("date", "lNifty"))
> summary(A)
         date lNifty
 2000-06-12: 1 Min. : 854.2
 2000-06-13: 1 1st Qu.:1032.8
 2000-06-15: 1 Median :1088.7
 2000-06-16: 1 Mean :1123.6
 2000-06-19: 1 3rd Qu.:1178.7
 2000-06-20: 1 Max. :1533.3
 (Other) :780
> oneindex(A$lNifty)
   Min. 1st Qu. Median Mean 3rd Qu. Max.
  854.2 1033.0 1089.0 1124.0 1179.0 1533.0

Here you see the median showing up as 1088.7 in the 1st case but
1089.0 in the 2nd case. How could that happen?

-- 
Ajay Shah                                                   Consultant
ajayshah@mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Fri 23 Apr 2004 - 18:36:27 EST