Skip to content
Prev 45051 / 398528 Next

Confused in simplest-possible function

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 :
+       summary(x)
+ }
+                 col.names=c("date", "lNifty"))
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
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?