corr.test(test[2:6], use = 'pairwise')
です。文字ベクトルである最初の列を除外する必要があります。以下は出力付きのreprexです。係数とp値が得られます。
library('tidyverse')
#> ── Attaching packages ─────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
#> ✔ ggplot2 2.2.1 ✔ purrr 0.2.4
#> ✔ tibble 1.3.4 ✔ dplyr 0.7.4
#> ✔ tidyr 0.7.2 ✔ stringr 1.2.0
#> ✔ readr 1.1.1 ✔ forcats 0.2.0
#> ── Conflicts ────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
#> ✖ dplyr::filter() masks stats::filter()
#> ✖ dplyr::lag() masks stats::lag()
library('psych')
#>
#> Attaching package: 'psych'
#> The following objects are masked from 'package:ggplot2':
#>
#> %+%, alpha
test = tibble::tribble(
~Group, ~V1, ~V2, ~V3, ~V4, ~V5,
'OH', 0.3, 5, -3.09, 2.5, NA,
'OH', 0.5, 1, NA, 1.8, 2.5,
'ON', 2 , 2.5, NA, -3.11, -7.5,
'OH', 1.5, -3.35, -0.82, NA, -2.5,
'ON', 6.5, -2.85, 2.5, NA, NA,
'OH', 3, 0.5, 1.8, -2.85, NA
)
corr.test(test[2:6], use = 'pairwise')
#> Warning in sqrt(n - 2): NaNs produced
#> Warning in corr.test(test[2:6], use = "pairwise"): Number of subjects must
#> be greater than 3 to find confidence intervals.
#> Warning in sqrt(n[lower.tri(n)] - 3): NaNs produced
#> Call:corr.test(x = test[2:6], use = "pairwise")
#> Correlation matrix
#> V1 V2 V3 V4 V5
#> V1 1.00 -0.59 0.89 -0.94 -0.98
#> V2 -0.59 1.00 -0.64 0.49 -0.25
#> V3 0.89 -0.64 1.00 -1.00 NA
#> V4 -0.94 0.49 -1.00 1.00 1.00
#> V5 -0.98 -0.25 NA 1.00 1.00
#> Sample Size
#> V1 V2 V3 V4 V5
#> V1 6 6 4 4 3
#> V2 6 6 4 4 3
#> V3 4 4 4 2 1
#> V4 4 4 2 4 2
#> V5 3 3 1 2 3
#> Probability values (Entries above the diagonal are adjusted for multiple tests.)
#> V1 V2 V3 V4 V5
#> V1 0.00 0.86 0.66 0.45 0.66
#> V2 0.22 0.00 1.00 1.00 1.00
#> V3 0.11 0.36 0.00 NaN NA
#> V4 0.06 0.51 NaN 0.00 NaN
#> V5 0.12 0.84 NA NaN 0.00
#>
#> To see confidence intervals of the correlations, print with the short=FALSE option
それはあなたがそれを提供するものだから、だけでなく 'Group'列を使用しようとしています。 (私はあなたの残りの列が実際に数値であると仮定しています;あなたもそれをチェックするかもしれません) – joran
データセットに数値列だけを残し、 'corr.test(mydataset、use =" pairwise ")'を実行します。このコマンドは、NAsを自動的に除外します。それが提供するサンプル表で確認できます。 – AntoniosK