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

From: <HDoran_at_air.org>
Date: Thu, 20 Sep 2007 23:22:18 +0200 (CEST)

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),
# 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

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

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 21 Sep 2007 - 12:29:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Sep 2007 - 12:41:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.