[Rd] Bug with Cor(..., method='spearman") and by() (PR#9921)

HDoran at air.org HDoran at air.org
Thu Sep 20 23:22:18 CEST 2007


I posted this on R help, and a few others responded indicating they too
were able to replicate the error as a function of missing data. I
believe this should not be the case and hence and reporting it here.

### Code provided on R-Help by Ivar Herfindal
# Simulate data
testdata <- cbind.data.frame(gr=3Drep(letters[1:4], each=3D5), =
aa=3Drnorm(20),
bb=3Drnorm(20))
# Introduce some missingness
testdata[1:5, 2] <- NA

# This works fine
by(testdata[,c("aa", "bb")], testdata$gr, cor, use=3D"complete",
method=3D"pearson")

# This induces error
by(testdata[,c("aa", "bb")], testdata$gr, cor, use=3D"complete",
method=3D"spearman")

Error in FUN(data[x, ], ...) : 'x' is empty

## Alternatively, we can try this

# This works fine
by(testdata[,c('aa', 'bb')], testdata$gr, cor, use=3D'complete',
method=3D'pearson')

## This induces the same error
by(testdata[,c('aa', 'bb')], testdata$gr, cor, use=3D'complete',
method=3D'spearman')

Error in FUN(data[x, ], ...) : 'x' is empty

I am using Windows XP with session info below

Harold Doran


> sessionInfo()
R version 2.5.0 (2007-04-23)=20
i386-pc-mingw32=20

locale:
LC_COLLATE=3DEnglish_United States.1252;LC_CTYPE=3DEnglish_United
States.1252;LC_MONETARY=3DEnglish_United
States.1252;LC_NUMERIC=3DC;LC_TIME=3DEnglish_United States.1252

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"
"methods"   "base"    =20

other attached packages:
     mlmRev        lme4      Matrix     lattice=20
  "0.995-1" "0.99875-2" "0.99875-3"    "0.15-4"=20



More information about the R-devel mailing list