I’m new to R, but I have a microarray dataset. I have an NA value at one location, and I try to use impute.knn() from library(impute), but after running the matrix through the impute.knn() function, it seems to turn into another structure. Can anyone explain what’s going on?
> 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
It looks like the
impute.knnfunction returns a list which contains the matrix and other data regarding the imputation. Try using: