这是我的数据集的输出:
structure(list(Year = c("2021", "2021", "2021", "2021", "2021",
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021",
"2021", "2021", "2021", "2021", "2021", "2021", "2021", "2021",
"2021"), Month_Number = c("8", "8", "8", "9", "9", "9", "9",
"9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9", "9",
"9", "9"), Month_Name = c("August", "August", "August", "September",
"September", "September", "September", "September", "September",
"September", "September", "September", "September", "September",
"September", "September", "September", "September", "September",
"September", "September", "September"), Day_Number = c(29L, 30L,
31L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L), Day_Name = c("Sunday", "Monday",
"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday",
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"), Time_Wake = c(730L, 800L, 730L, 500L,
715L, 600L, 600L, 700L, 600L, 700L, 500L, 500L, 500L, 500L, 700L,
645L, 700L, 630L, 645L, 700L, 600L, 700L), Start_Work = c(1400L,
1100L, 930L, 1015L, 1000L, 945L, 1400L, 1500L, 915L, 930L, 1000L,
940L, 840L, 730L, 1700L, 945L, 1040L, 955L, 945L, 930L, 745L,
800L), End_Work = c(1900L, 1755L, 1520L, 1800L, 1600L, 1210L,
1700L, 1515L, 1530L, 1530L, 1800L, 1650L, 1800L, 1410L, 2000L,
1710L, 1430L, 1800L, 1840L, 1720L, 1915L, NA), Mins_Sleep = c(420L,
360L, 360L, 300L, 540L, 540L, 480L, 480L, 480L, 480L, 420L, 300L,
240L, 480L, 300L, 420L, 360L, 390L, 405L, 420L, 360L, 420L),
Workout_Y_N = c("N", "Y", "N", "Y", "Y", "Y", "N", "N", "N",
"N", "Y", "Y", "N", "N", "N", "N", "Y", "Y", "Y", "N", "N",
""), Time_Workout = c(NA, NA, NA, 730L, 730L, 730L, NA, NA,
NA, NA, 730L, 730L, NA, NA, NA, NA, 735L, 735L, 735L, NA,
NA, NA), Work_Environment = c("Home", "Office", "Office",
"Office", "Office", "Office", "Home", "Home", "Office", "Office",
"Office", "Office", "Office", "Home", "Home", "Office", "Office",
"Office", "Home", "Office", "Home", "Home"), Coffee_Cups = c(4L,
0L, 1L, 3L, 0L, 2L, 6L, 4L, 5L, 3L, 3L, 2L, 2L, 3L, 1L, 1L,
3L, 2L, 2L, 0L, 1L, 1L), Tea_Cups = c(0L, 2L, 2L, 2L, 4L,
2L, 0L, 0L, 2L, 0L, 2L, 4L, 0L, 0L, 0L, 2L, 6L, 5L, 0L, 2L,
0L, 0L), Mins_Work = c(300L, 420L, 310L, 435L, 350L, 145L,
135L, 15L, 60L, 60L, 390L, 395L, 395L, 315L, 80L, 580L, 175L,
545L, 230L, 435L, 370L, NA), Onset_Mood = c("Tired", "Tired",
"Sad", "Angry", "Rested", "Rested", "Rested", "Tired", "Tired",
"Tired", "Rested", "Angry", "Tired", "Rested", "Angry", "Angry",
"Angry", "Sad", "Rested", "Sad", "Tired", "Tired")), class = "data.frame", row.names = c(NA,
-22L))
我只是想在变量之间运行部分相关性"Coffee_Cups
";和";Mins_Work
";受控于"Day_Name
"。但是,当我从ppcor库运行这个部分相关性时:
library(ppcor)
pcor.test(x=work$Mins_Work,
y=work$Coffee_Cups,
z=work$Day_Name)
它给了我这个错误:
pcor(xyz, method = method): 'x'时出错(中文= "需要是一个数值")
我尝试切换x和y变量,但这似乎也没有影响,尽管两者都是数值。我是不是做错了什么?
参见pcor.test
的文档,它说Missing values are not allowed
。变量Mins_Work
缺少值NA
。
work$Mins_Work
[1] 300 420 310 435 350 145 135 15 60 60 390 395 395 315 80 580 175 545 230 435 370 NA
此外,所有变量都需要是数字,但变量Day_Name
不是。
work$Day_Name
[1] "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday"
[13] "Friday" "Saturday" "Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday" "Sunday"