Skip to content

Warning message: NAs introduced by coercion

10 messages · N Meriam, Michael Dewey, David L Carlson +1 more

#
Dear all,

I have a .csv file called df4. (15752 obs. of 264 variables).
I apply this code but couldn't continue further other analyses, a warning
message keeps coming up. Then, I want to determine max and min
similarity values,
heat map plot, cluster...etc
myd[,1]
# the data must be 0,1,2 with 3 as missing so you have r
# genotype data must have - in 3
*Warning message:In class(genod) <- "numeric" : NAs introduced by coercion*

Maybe I could illustrate more with details so I can be more specific?
Please, let me know.

I would appreciate your help.
Thanks,
Meriam
#
Hi

see in line
matrix can have only one type of data so you probaly changed it to character by such construction.
This tries to change all "numeric" values to numbers but if it cannot it sets it to NA.

something like
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 "5.1"        "3.5"       "1.4"        "0.2"       "setosa"
2 "4.9"        "3.0"       "1.4"        "0.2"       "setosa"
3 "4.7"        "3.2"       "1.3"        "0.2"       "setosa"
4 "4.6"        "3.1"       "1.5"        "0.2"       "setosa"
5 "5.0"        "3.6"       "1.4"        "0.2"       "setosa"
6 "5.4"        "3.9"       "1.7"        "0.4"       "setosa"
Warning message:
In class(irm) <- "numeric" : NAs introduced by coercion
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2      NA
2          4.9         3.0          1.4         0.2      NA
3          4.7         3.2          1.3         0.2      NA
4          4.6         3.1          1.5         0.2      NA
5          5.0         3.6          1.4         0.2      NA
6          5.4         3.9          1.7         0.4      NA
Cheers
Petr
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner?s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
#
I see...
Here's a portion of what my data looks like (csv file attached).
I run again and here are the results:

df4 <- read.csv(file = "mydata.csv", header = TRUE)
[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"
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
is.matrix(genmat) is not TRUE

Thanks,
Meriam
On Tue, Jan 8, 2019 at 9:02 AM PIKAL Petr <petr.pikal at precheza.cz> wrote:

            

  
    
#
Dear Meriam

Your csv file did not come through as attachments are stripped unless of 
certain types and you post is very hard to read since you are posting in 
HTML. Try renaming the file to ????.txt and set your mailer to send 
plain text then people may be able to help you better.

Michael
On 08/01/2019 15:35, N Meriam wrote:

  
    
  
#
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:

  
    
#
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:

  
    
#
Yes, sorry. I attached the file once again.
Well, still getting the same warning.
Warning message:
In class(genod) <- "numeric" : NAs introduced by coercion
[1] "matrix"

Then, I run the following code and it gives this:
+                  sample.id = sample.id, snp.id = snp.id,
+                  snp.chromosome = snp.chromosome,
+                  snp.position = snp.position,
+                  snp.allele = snp.allele, snpfirstdim=TRUE)
File: C:\Users\DELL\Documents\TEST\simTunesian.gds (1.4M)
+    [  ] *
|--+ sample.id   { Str8 363 ZIP_ra(42.5%), 755B }
|--+ snp.id   { Int32 15752 ZIP_ra(35.1%), 21.6K }
|--+ snp.position   { Int32 15752 ZIP_ra(34.7%), 21.3K }
|--+ snp.chromosome   { Float64 15752 ZIP_ra(0.18%), 230B }
|--+ snp.allele   { Str8 15752 ZIP_ra(0.16%), 108B }
\--+ genotype   { Bit2 15752x363, 1.4M } *
Identity-By-State (IBS) analysis on genotypes:
Excluding 0 SNP on non-autosomes
Working space: 363 samples, 15,752 SNPs
    using 1 (CPU) core
IBS:    the sum of all selected genotypes (0,1,2) = 3658952
Tue Jan 08 15:38:00 2019    (internal increment: 42880)
[==================================================] 100%, completed in 0s
Tue Jan 08 15:38:00 2019    Done.
[1] NaN
[1] NaN

As you can see, I can't continue my analysis (heat map plot,
clustering with hclust) because values are NaN.
On Tue, Jan 8, 2019 at 2:01 PM David L Carlson <dcarlson at tamu.edu> wrote:

  
    
#
Hm,

you should use dput for sharing data but my suggestion was correct.

You converted genod to genod2 by as.matrix what changed it to ?character? matrix as matrix is able to hold only one type of data. By trying to change it to numeric, all numbers are changed to numeric and what cannot be changed is simply converted to NA (with polite warning).

You should read documentation to
snpgdsCreateGeno
as it requires matrix as an input and maybe also pay attention to the basic documents like R-intro which would teach you difference between matrix and data frame (chapter 3).

Cheers
Petr


From: N Meriam <meriam.nef at gmail.com>
Sent: Tuesday, January 8, 2019 4:36 PM
To: PIKAL Petr <petr.pikal at precheza.cz>
Cc: r-help at r-project.org
Subject: Re: [R] Warning message: NAs introduced by coercion

I see...
Here's a portion of what my data looks like (csv file attached).
I run again and here are the results:


df4 <- read.csv(file = "mydata.csv", header = TRUE)
[1] "marker" "X88"    "X9"     "X17"    "X25"
[1]  3  4  5  6  8 10
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"
+                  sample.id<http://sample.id> = sample.id<http://sample.id>, snp.id<http://snp.id> = snp.id<http://snp.id>,

+                  snp.chromosome = snp.chromosome,

+                  snp.position = snp.position,

+                  snp.allele = snp.allele, snpfirstdim=TRUE)

Error in snpgdsCreateGeno(filn, genmat = genod, sample.id<http://sample.id> = sample.id<http://sample.id>,  :

  is.matrix(genmat) is not TRUE
Thanks,
Meriam
On Tue, Jan 8, 2019 at 9:02 AM PIKAL Petr <petr.pikal at precheza.cz<mailto:petr.pikal at precheza.cz>> wrote:
Hi

see in line
matrix can have only one type of data so you probaly changed it to character by such construction.
This tries to change all "numeric" values to numbers but if it cannot it sets it to NA.

something like
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 "5.1"        "3.5"       "1.4"        "0.2"       "setosa"
2 "4.9"        "3.0"       "1.4"        "0.2"       "setosa"
3 "4.7"        "3.2"       "1.3"        "0.2"       "setosa"
4 "4.6"        "3.1"       "1.5"        "0.2"       "setosa"
5 "5.0"        "3.6"       "1.4"        "0.2"       "setosa"
6 "5.4"        "3.9"       "1.7"        "0.4"       "setosa"
Warning message:
In class(irm) <- "numeric" : NAs introduced by coercion
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2      NA
2          4.9         3.0          1.4         0.2      NA
3          4.7         3.2          1.3         0.2      NA
4          4.6         3.1          1.5         0.2      NA
5          5.0         3.6          1.4         0.2      NA
6          5.4         3.9          1.7         0.4      NA
Cheers
Petr
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner?s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/


--
Meriam Nefzaoui
MSc. in Plant Breeding and Genetics
Universidade Federal Rural de Pernambuco (UFRPE) - Recife, Brazil
#
And as you use bioconductor related package you probably could get better answers in specialised biconductor help

https://www.bioconductor.org/help/

Cheers
Petr

From: N Meriam <meriam.nef at gmail.com>
Sent: Tuesday, January 8, 2019 4:36 PM
To: PIKAL Petr <petr.pikal at precheza.cz>
Cc: r-help at r-project.org
Subject: Re: [R] Warning message: NAs introduced by coercion

I see...
Here's a portion of what my data looks like (csv file attached).
I run again and here are the results:


df4 <- read.csv(file = "mydata.csv", header = TRUE)
[1] "marker" "X88"    "X9"     "X17"    "X25"
[1]  3  4  5  6  8 10
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"
+                  sample.id<http://sample.id> = sample.id<http://sample.id>, snp.id<http://snp.id> = snp.id<http://snp.id>,

+                  snp.chromosome = snp.chromosome,

+                  snp.position = snp.position,

+                  snp.allele = snp.allele, snpfirstdim=TRUE)

Error in snpgdsCreateGeno(filn, genmat = genod, sample.id<http://sample.id> = sample.id<http://sample.id>,  :

  is.matrix(genmat) is not TRUE
Thanks,
Meriam
On Tue, Jan 8, 2019 at 9:02 AM PIKAL Petr <petr.pikal at precheza.cz<mailto:petr.pikal at precheza.cz>> wrote:
Hi

see in line
matrix can have only one type of data so you probaly changed it to character by such construction.
This tries to change all "numeric" values to numbers but if it cannot it sets it to NA.

something like
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 "5.1"        "3.5"       "1.4"        "0.2"       "setosa"
2 "4.9"        "3.0"       "1.4"        "0.2"       "setosa"
3 "4.7"        "3.2"       "1.3"        "0.2"       "setosa"
4 "4.6"        "3.1"       "1.5"        "0.2"       "setosa"
5 "5.0"        "3.6"       "1.4"        "0.2"       "setosa"
6 "5.4"        "3.9"       "1.7"        "0.4"       "setosa"
Warning message:
In class(irm) <- "numeric" : NAs introduced by coercion
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2      NA
2          4.9         3.0          1.4         0.2      NA
3          4.7         3.2          1.3         0.2      NA
4          4.6         3.1          1.5         0.2      NA
5          5.0         3.6          1.4         0.2      NA
6          5.4         3.9          1.7         0.4      NA
Cheers
Petr
Osobn? ?daje: Informace o zpracov?n? a ochran? osobn?ch ?daj? obchodn?ch partner? PRECHEZA a.s. jsou zve?ejn?ny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner?s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/
D?v?rnost: Tento e-mail a jak?koliv k n?mu p?ipojen? dokumenty jsou d?v?rn? a podl?haj? tomuto pr?vn? z?vazn?mu prohl??en? o vylou?en? odpov?dnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/


--
Meriam Nefzaoui
MSc. in Plant Breeding and Genetics
Universidade Federal Rural de Pernambuco (UFRPE) - Recife, Brazil
#
Now you have pushed a numeric matrix to the function with a column of missing values. No wonder you do not get any results. 

David C

-----Original Message-----
From: N Meriam [mailto:meriam.nef at gmail.com] 
Sent: Tuesday, January 8, 2019 3:44 PM
To: David L Carlson <dcarlson at tamu.edu>
Cc: Michael Dewey <lists at dewey.myzen.co.uk>; r-help at r-project.org
Subject: Re: [R] Warning message: NAs introduced by coercion

Yes, sorry. I attached the file once again.
Well, still getting the same warning.
Warning message:
In class(genod) <- "numeric" : NAs introduced by coercion
[1] "matrix"

Then, I run the following code and it gives this:
+                  sample.id = sample.id, snp.id = snp.id,
+                  snp.chromosome = snp.chromosome,
+                  snp.position = snp.position,
+                  snp.allele = snp.allele, snpfirstdim=TRUE)
File: C:\Users\DELL\Documents\TEST\simTunesian.gds (1.4M)
+    [  ] *
|--+ sample.id   { Str8 363 ZIP_ra(42.5%), 755B }
|--+ snp.id   { Int32 15752 ZIP_ra(35.1%), 21.6K }
|--+ snp.position   { Int32 15752 ZIP_ra(34.7%), 21.3K }
|--+ snp.chromosome   { Float64 15752 ZIP_ra(0.18%), 230B }
|--+ snp.allele   { Str8 15752 ZIP_ra(0.16%), 108B }
\--+ genotype   { Bit2 15752x363, 1.4M } *
Identity-By-State (IBS) analysis on genotypes:
Excluding 0 SNP on non-autosomes
Working space: 363 samples, 15,752 SNPs
    using 1 (CPU) core
IBS:    the sum of all selected genotypes (0,1,2) = 3658952
Tue Jan 08 15:38:00 2019    (internal increment: 42880)
[==================================================] 100%, completed in 0s
Tue Jan 08 15:38:00 2019    Done.
[1] NaN
[1] NaN

As you can see, I can't continue my analysis (heat map plot,
clustering with hclust) because values are NaN.
On Tue, Jan 8, 2019 at 2:01 PM David L Carlson <dcarlson at tamu.edu> wrote: