Question: SOLVED: how to change SnpMatrix in to numeric
0
gravatar for zwang10
2.1 years ago by
zwang100
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

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

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.4k views
ADD COMMENTlink modified 6 months ago by catherinem.ross0 • written 2.1 years ago by zwang100

If this is solved, could you post your solution please

ADD REPLYlink written 2.0 years ago by russhh3.7k
0
gravatar for catherinem.ross
6 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 6 months ago • written 6 months ago by catherinem.ross0
Please log in to add an answer.

Help
Access

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