Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return NA if either sd in the denominator is 0. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chinandrew
Copy link

Fixes #1.

Checks if the standard deviations are close to 0 and returns NA if so, since otherwise would be dividing by 0.
Threshold I'm using is about 1.49e-8, which is based on the same threshold used by dplyr's near()

> devtools::load_all()
ℹ Loading dvmisc
> set.seed(87)
> dvmisc::sliding_cor(runif(25), rep(1.014103, 40))
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> set.seed(100)
> dvmisc::sliding_cor(runif(25), rep(1.014103, 40)) 
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> set.seed(100)
> dvmisc::sliding_cor(runif(30), rep(1.014103, 40)) 
 [1] NA NA NA NA NA NA NA NA NA NA NA
> set.seed(100)
> dvmisc::sliding_cor(runif(20), rep(1.014103, 40))
 [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> set.seed(100)
> dvmisc::sliding_cor(rep(1.014103, 40), runif(50))
 [1] NA NA NA NA NA NA NA NA NA NA NA

(Included one additional example at the end if sd_shortvec is ~0, not just longvec).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with zero variance
1 participant