R 中字符矩阵转化为数值矩阵

a.str <- matrix(c(‘1′,’2′,’3′,’5′,NA,’6′)
+ ,c(2,3),dimnames = list(c(‘g1′,’g2′),c(‘t1′,’t2′,’t3′)))

a.str
#      t1  t2  t3
# g1 “1” “3” NA
# g2 “2” “5” “6”

a.num <- apply(a.str, c(1,2), as.numeric)

a.num
#    t1 t2 t3
# g1  1  3 NA
# g2  2  5  6

Note: 第一行,第一列位置要为空!!

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>