我有一个由元素及其评级组成的矩阵,例如
matrix(data=c("A","B","C",NA,0.7,0.5,0,NA,"D","E","F","G",0.9,0.4,0.2,0.005),nrow=4,byrow=FALSE)
[,1] [,2] [,3] [,4]
[1,] "A" "0.7" "D" "0.9"
[2,] "B" "0.5" "E" "0.4"
[3,] "C" "0" "F" "0.2"
[4,] NA NA "G" "0.005"
我想用 NA 替换所有小于 0.1 的评级(以及它们旁边的元素)。
例如
matrix(data=c("A","B",NA,NA,0.7,0.5,NA,NA,"D","E","F",NA,0.9,0.4,0.2,NA),nrow=4, byrow=FALSE)
[,1] [,2] [,3] [,4]
[1,] "A" "0.7" "D" "0.9"
[2,] "B" "0.5" "E" "0.4"
[3,] NA NA "F" "0.2"
[4,] NA NA NA NA
当我认为必须有更好的方法时,我正要在一个大的 for 循环中执行此操作。任何建议将不胜感激。