Skip to content
Prev 155682 / 398502 Next

making spearman correlation cor() call fail with log(0) as input

Your code shows no errors only correct responses.

If you want an error when R is generating correct results, you will need to check for the conditions yourself.

-----Original Message-----
From: "Timur Shtatland" <tshtatland at gmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Sent: 9/10/08 3:51 PM
Subject: [R] making spearman correlation cor() call fail with log(0) as input


Hi,

How can I make the cor(x, y, method="spearman") call to produce an
error when the input to it (x, y) produces an error? Here is a simple
example:
## error:
[1]      -Inf 0.0000000 0.6931472

## error, as expected:
[1] NaN

## not an error any more (not expected):
[1] -0.5
[1] -0.5
R version 2.6.1 (2007-11-26)
i686-pc-linux-gnu

locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
Thank you for your help.

Best regards,

Timur Shtatland

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.