[R] Confused in simplest-possible function
Ajay Shah
ajayshah at mayin.org
Sun Feb 29 18:14:21 CET 2004
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 at mayin.org Department of Economic Affairs
http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
More information about the R-help
mailing list