我有一个data.table如下;
rn Df Sum Sq Mean Sq F value Pr(>F)
1 Preperations 1 96.0399999999997 96.0399999999997 34.9713245334545 0.000356224698621559
2 Regression 1 1354.658 1354.658 493.275557578514 1.78526751428199e-08
3 Non-Parallelism 1 1.40450000000004 1.40450000000004 0.511424670004565 0.494860891043109
4 Non-Linearity 4 2.06499999999999 0.516249999999997 0.187983614019115 0.938069215994797
5 Standard 2 0.241500000000019 0.120750000000009 NA NA
6 FXIa 2 1.82350000000001 0.911750000000006 0.174039608685277 0.846301453798201
7 Treatments 7 1454.1675 207.738214285714 75.6443201768642 1.11726989674841e-06
8 Residual error 8 21.9700000000001 2.74625000000001 NA NA
9 Total 15 1476.1375 98.4091666666666 NA NA
我试图通过dt[rn == "Standard",`Mean Sq`]
潜入单元dt[rn == "Residual error",`Mean Sq`]
并将其放入单元格dt[rn == "Standard,`F Value`]
经过一些研究之后,它似乎是因为列是因素,而不是数字,为什么它不能工作但不知道从哪里开始。
这是一个可重现的例子
test <- data.table(data.frame(matrix(c(
"Preperations", 1 ,96.0399999999997 ,96.0399999999997 ,34.9713245334545 ,0.000356224698621559,
"Regression" , 1 ,1354.658 ,1354.658 ,493.275557578514 ,1.78526751428199e-08,
"Non-Parallelism", 1 ,1.40450000000004 ,1.40450000000004 ,0.511424670004565 ,0.494860891043109,
"Non-Linearity" , 4 ,2.06499999999999 ,0.516249999999997 ,0.187983614019115 ,0.938069215994797,
"Standard" , 2 ,0.241500000000019, 0.120750000000009 ,NA ,NA,
"FXIa" , 2 ,1.82350000000001 ,0.911750000000006 ,0.174039608685277 ,0.846301453798201,
"Treatments" , 7 ,1454.1675 , 207.738214285714 ,75.6443201768642 ,1.11726989674841e-06,
"Residual error", 8 ,21.9700000000001 ,2.74625000000001 ,NA ,NA,
"Total" , 15 ,1476.1375 , 98.4091666666666 ,NA , NA),
ncol=6,byrow=TRUE),stringsAsFactors=TRUE))
setnames(test,old=names(test),new =c( "rn", "Df", "Sum Sq", "Mean Sq", "F value", "Pr(>F)"))