Skip to content

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