Skip to content
Prev 378098 / 398502 Next

Warning message: NAs introduced by coercion

Your attached file is not a .csv file since the field are not separated by commas (just rename the mydata.csv to mydata.txt).

The command "genod2 <- as.matrix(genod)" created a character matrix from the data frame genod.  When you try to force genod2 to numeric, the marker column becomes NAs which is probably not what you want.

The error message is because you passed genod (a data frame) to the snpgdsCreateGeno() function not genod2 (the matrix you created from genod).

------------------------------------
David L. Carlson
Department of Anthropology
Texas A&M University

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of N Meriam
Sent: Tuesday, January 8, 2019 1:38 PM
To: Michael Dewey <lists at dewey.myzen.co.uk>
Cc: r-help at r-project.org
Subject: Re: [R] Warning message: NAs introduced by coercion

Here's a portion of what my data looks like (text file format attached).
When running in R, it gives me this:
[1] "marker" "X88"    "X9"     "X17"    "X25"
[1]  3  4  5  6  8 10
# the data must be 0,1,2 with 3 as missing so you have r
# genotype data must have - in 3
marker                                             X88   X9
 X17   X25
[1,]  "100023173|F|0-47:G>A-47:G>A"     "0"    "3"    "3"     "3"
[2,]  "1043336|F|0-7:A>G-7:A>G"             "2"    "0"    "3"     "0"
[3,]  "1212218|F|0-49:A>G-49:A>G"         "0"    "0"    "0"     "0"
[4,]  "1019554|F|0-14:T>C-14:T>C"           "0"   "0"    "3"     "0"
[5,]  "100024550|F|0-16:G>A-16:G>A"     "3"    "3"    "3"     "3"
[6,]  "1106702|F|0-8:C>A-8:C>A"              "0"   "0"     "0"     "0"
Warning message: In class(genod2) <- "numeric" : NAs introduced by coercion
marker   X88  X9   X17  X25
[1,]     NA         0      3     3       3
[2,]     NA         2      0     3       0
[3,]     NA         0      0     0       0
[4,]     NA         0      0     3       0
[5,]     NA         3      3     3       3
[6,]     NA         0      0     0       0
[1] "matrix"
# read data
+                  sample.id = sample.id, snp.id = snp.id,
+                  snp.chromosome = snp.chromosome,
+                  snp.position = snp.position,
+                  snp.allele = snp.allele, snpfirstdim=TRUE)
Error in snpgdsCreateGeno(filn, genmat = genod, sample.id = sample.id,
 :   is.matrix(genmat) is not TRUE

Can't find a solution to my problem...my guess is that the problem
comes from converting the column 'marker' factor to numerical.

Best,
Meriam
On Tue, Jan 8, 2019 at 11:28 AM Michael Dewey <lists at dewey.myzen.co.uk> wrote: