Question: SOLVED: how to change SnpMatrix in to numeric
gravatar for zwang10
2.6 years ago by
United States
zwang100 wrote:

I use read.plink from package snpStats. I use following to read bed file, and I want to get the 0,1,2 matrix.

GENOTYPE=read.plink("chr22_1",na.strings = "NA")

Then, from the manuals, I know there is a "genotypes" value of GNEOTYPE, which is an object of class "SnpMatrix". And I got this

> genotype$genotypes
A SnpMatrix with  1497 rows and  6 columns
Row names:  ALS5085249 ... ALS5227466 
Col names:  rs62224609 ... rs62224618

Can someone tell me how to change it into 0,1,2 matrix?

My work, I tried to use


And I got something like this, which is not numeric.

           rs62224609 rs80167676 rs3013006 rs9604721 rs117246541 rs62224618
ALS5085249 "B/B"      "B/B"      "B/B"     "B/B"     "B/B"       "B/B"     
ALS5085250 "B/B"      "B/B"      "A/B"     "B/B"     "B/B"       "B/B"     
ALS5085251 "A/B"      "A/B"      "B/B"     "B/B"     "A/B"       "A/B"     
ALS5085252 "B/B"      "B/B"      "A/B"     "B/B"     "B/B"       "B/B"     
ALS5085253 "B/B"      "B/B"      "B/B"     "B/B"     "B/B"       "B/B"     
ALS5085254 "A/B"      "B/B"      "A/B"     "B/B"     "B/B"       "A/B"     
Warning message:
In coerce(genotype$genotypes, to = "numeric") :
  direct use of coerce() is deprecated:  use as(from, class(to)) instead
snpmatrix R • 1.9k views
ADD COMMENTlink modified 12 months ago by catherinem.ross0 • written 2.6 years ago by zwang100

If this is solved, could you post your solution please

ADD REPLYlink written 2.5 years ago by russhh4.2k
gravatar for catherinem.ross
12 months ago by
catherinem.ross0 wrote:

Use the function indicated in the warning message:

as(genotype$genotypes, to="numeric")

the coerce function is deprecated.

ADD COMMENTlink modified 12 months ago • written 12 months ago by catherinem.ross0
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1798 users visited in the last hour