Learn R Programming

ldsep (version 2.1.5)

slcor: Sliding window correlation

Description

Calculates the pairwise Pearson correlation between all columns within a fixed window size (win) using the use = "pairwise.complete.obs" option from cor(). That is, the correlation between each pair of variables is computed using all complete pairs of observations on those variables.

Usage

slcor(x, win = 1L)

Value

A correlation matrix with only the observations within a window containing calculated correlations.

Arguments

x

A numeric matrix. The variables index the columns.

win

The size of the window. Defaults to 1.

Author

David Gerard

Examples

Run this code
set.seed(1)
n <- 10
p <- 100
xmat <- matrix(rnorm(n * p), ncol = n)
xmat[sample(n * p, size = 30)] <- NA_real_
slcor(xmat, win = 2)

Run the code above in your browser using DataLab