rcorr will run correctly with 0 entries
library(Hmisc)
#> Loading required package: lattice
#> Loading required package: survival
#> Loading required package: Formula
#> Loading required package: ggplot2
#>
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:base':
#>
#> format.pval, units
x <- c(-2, -1, 0, 1, 2)
y <- c(4, 1, 0, 1, 4)
z <- c(1, 2, 3, 4, NA)
v <- c(1, 2, 3, 4, 5)
rcorr(cbind(x,y,z,v))
#> x y z v
#> x 1 0.00 1.00 1
#> y 0 1.00 -0.75 0
#> z 1 -0.75 1.00 1
#> v 1 0.00 1.00 1
#>
#> n
#> x y z v
#> x 5 5 4 5
#> y 5 5 4 5
#> z 4 4 4 4
#> v 5 5 4 5
#>
#> P
#> x y z v
#> x 1.0000 0.0000 0.0000
#> y 1.0000 0.2546 1.0000
#> z 0.0000 0.2546 0.0000
#> v 0.0000 1.0000 0.0000
Created on 2020-08-11 by the reprex package (v0.3.0)
It has no way of knowing, however, if 0 correctly encodes an observation of 0 or a non-observation, which should always be NA.
library(Hmisc)
#> Loading required package: lattice
#> Loading required package: survival
#> Loading required package: Formula
#> Loading required package: ggplot2
#>
#> Attaching package: 'Hmisc'
#> The following objects are masked from 'package:base':
#>
#> format.pval, units
x <- c(-2, -1, NA, 1, 2)
y <- c(4, 1, NA, 1, 4)
z <- c(1, 2, 3, 4, NA)
v <- c(1, 2, 3, 4, 5)
rcorr(cbind(x,y,z,v))
#> x y z v
#> x 1 0.00 1.00 1
#> y 0 1.00 -0.76 0
#> z 1 -0.76 1.00 1
#> v 1 0.00 1.00 1
#>
#> n
#> x y z v
#> x 4 4 3 4
#> y 4 4 3 4
#> z 3 3 4 4
#> v 4 4 4 5
#>
#> P
#> x y z v
#> x 1.0000 0.0000 0.0000
#> y 1.0000 0.4544 1.0000
#> z 0.0000 0.4544 0.0000
#> v 0.0000 1.0000 0.0000
Created on 2020-08-11 by the reprex package (v0.3.0)
See also, help(rcorr)
rcorr returns a list with elements r, the matrix of correlations, n the matrix of number of observations used in analyzing each pair of variables, and P, the asymptotic P-values. Pairs with fewer than 2 non-missing values have the r values set to NA. The diagonals of n are the number of non-NAs for the single variable corresponding to that row and column.