这是我的数据集,我是 R 新手,我正在尝试为此数据集编写脚本。
R> head(KenTau)
Age CapReg TrSw FeelChk CanSw
1 20 1 0 0 0
2 36 1 0 0 0
3 35 1 3 2 2
4 21 0 0 2 2
5 43 0 0 2 2
6 34 1 0 0 0
我想将 TrSw 与 colmn 变量的其余部分进行比较,即
TrSw Vs Age
TrSw Vs CapReg
TrSw Vs FeelChk
TrSw Vs CanSw
我用这个在 R 上运行它,我用这个命令
cor.test(KenTau$Age, KenTau$TrSw, alternative="two.sided", method="kendall")
我还想提取 Age 和 pvalue 以便我可以有一个列表,因为我有接近 50 个变量。
dput()
数据的:
KenTau <- structure(list(Age = c(20L, 36L, 35L, 21L, 43L, 34L, 37L, 62L,
54L, 47L, 48L, 45L, 2L, 2L, 2L, 54L, 52L, 40L, 58L, 29L, 27L,
28L, 46L, 35L, 50L, 31L, 48L, 2L, 29L, 54L, 52L, 28L, 28L, 26L,
38L, 59L, 51L, 58L, 39L, 44L, 53L, 2L, 39L, 55L, 48L, 2L, 23L,
51L, 50L, 26L, 28L, 40L, 38L, 61L, 52L, 33L, 2L, 59L, 27L, 45L,
45L, 57L, 66L, 52L, 58L, 34L, 28L, 39L, 48L, 53L, 39L, 46L, 57L,
36L, 25L, 22L, 29L, 46L, 25L, 25L, 35L, 44L, 24L, 26L, 33L, 27L,
41L, 28L, 26L, 32L, 36L, 35L, 32L, 33L, 29L, 29L, 52L, 55L, 23L,
29L, 45L, 26L, 48L, 54L, 50L, 35L, 27L, 39L, 41L, 30L, 30L, 31L,
27L, 28L, 27L, 25L, 34L, 23L, 30L, 34L, 52L, 20L, 31L, 2L, 45L,
34L, 21L, 60L, 34L, 40L, 47L, 30L, 54L, 36L, 32L, 31L, 55L, 57L,
23L, 31L, 26L, 26L, 27L, 19L, 26L, 25L, 37L, 47L, 38L, 38L, 26L,
25L, 41L), CapReg = c(1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L,
1L, 1L, 1L, 1L, 0L, 0L, 1L, 1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