我是R新手,但我有一個微陣列數據集。我在一個位置有一個NA值,我嘗試從庫(impute)使用impute.knn(),但是在通過impute.knn()函數運行矩陣後,它似乎變成另一個結構。任何人都可以解釋發生了什麼?當我通過impute.knn運行它時,Matrix會變成別的東西。
> m <- as.matrix(m)
# checking structure
> str(m)
num [1:22283, 1:20] 1942.1 40.1 72.1 4693.6 35.9 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:22283] "1007_s_at" "1053_at" "117_at" "121_at" ...
..$ : chr [1:20] "GSM146778-Normal" "GSM146780-Normal" "GSM146782-Normal"
# checking missing value of cell
> m[x,y]
[1] NA
# impute missing value
> m.i <- impute.knn(m, 6)
# check value of imputed value
> m.i[x,y]
Error in r.imp["206054_at", "GSM146784-Normal"] : incorrect number of dimensions
# check structure of imputed matrix
> str(m.i)
List of 3
$ data : num [1:22283, 1:20] 1942.1 40.1 72.1 4693.6 35.9 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:22283] "1007_s_at" "1053_at" "117_at" "121_at" ...
.. ..$ : chr [1:20] "GSM146778-Normal" "GSM146780-Normal" "GSM146782-Normal" "GSM146784-Normal" ...
$ rng.seed : num 3.62e+08
$ rng.state: int [1:626] 403 50 1992223309 -108730617 1600482030 698744776
什麼是'x',什麼是'y'?請發佈一個可重複的例子! - 包含數據的一部分 – mnel
@mnel,x和y是行/列名稱。詹姆斯解釋說,你可以用'$'字符來調用矩陣,所以我得到了我所需要的。謝謝你的幫助! –
很高興聽到您解決了您的問題,但發佈可重複使用的示例仍然不錯(如您在其他問題中所做的那樣) – mnel