I recently started using R 2.7.2, and noticed a surprising change in the behavior of var() on NA data:
R 2.6.1 (Patched), 2007-11-26, svn.rev 43541, x86_64-unknown-linux-gnu: > stdev(rep(NA,3), na.rm=F) [1] NA > stdev(rep(NA,3), na.rm=T) [1] NA > var(rep(NA,3), na.rm=T, use="complete.obs") [1] NA R 2.7.2 (Patched), 2008-09-02, svn.rev 46491, x86_64-unknown-linux-gnu: > stdev(rep(NA,3), na.rm=F) [1] NA > stdev(rep(NA,3), na.rm=T) Error in var(x, na.rm = na.rm) : no complete element pairs Enter a frame number, or 0 to exit 1: stdev(rep(NA, 3), na.rm = T) 2: var(x, na.rm = na.rm) Selection: 0 > var(rep(NA,3), na.rm=T, use="complete.obs") Error in var(rep(NA, 3), na.rm = T, use = "complete.obs") : no complete element pairs Is this change intentional? Also, what is causing it? Looking, I see no changes in var() at all, so the new behavior must be due to a change in what this call does: .Internal(cov(x, y, na.method, FALSE)) The R 2.7.2 cov() also has this weird line: else if (na.method != 3L) { Note the "L" in the "3L". A typo? The older 2.6.1 cov() just has "3" on that line, no "L". Interactively redefining cov() to remove the "L" makes no difference in my var() calls, but that could b The original source file seems to be: src/library/stats/R/cor.R svn annotate says that 3L line was last changed nearly a year ago, way back in rev 43302: ------------------------------------------------------------------------ r43302 | ripley | 2007-10-29 14:50:18 -0400 (Mon, 29 Oct 2007) | 2 lines make cor/cov a little less inconsistent The strange 3L line occurs twice in that file, in both cor() and cov(): $ grep -n 3L cor.R 36: else if (na.method != 3L) { 118: else if (na.method != 3L) { That line might not be the cause of my "no complete element pairs" problem (I'm not at all sure), but it does look suspicious. -- Andrew Piskorski <[EMAIL PROTECTED]> http://www.piskorski.com/ ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel