Why do big integers get deformed in R when I convert from a data frame or data table to a matrix? [duplicate]












0















This question already has an answer here:




  • How to convert a data frame of integer64 values to be a matrix?

    1 answer





  1. I have a data frame (1 x 30 in dimensions) made entirely of numeric columns (double and integer columns). Some of the integers are 10^12.

  2. When I convert the data frame to a matrix using as.matrix() function of base R, something strange happens, an integer like, for example here, 10978645435 would not stay the same in the new object (numeric matrix) but it becomes 5.076377571e-314

  3. I am aware of similar post on the site in which the user had encountered a similar problem but the answer to that post was about coercing column by column to integer64. This approach assumes that I know exactly my columns data type in advance. The answer is not robust at all or dynamic enough with all due respect.


Any idea why would this happen and how I could possibly fix the issue? Thanks in advance.










share|improve this question















marked as duplicate by Bill the Lizard, Hong Ooi, Ben Bolker r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 16:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    Can you post sample data in dput format? Please edit the question with the output of dput(df). Or, if it is too big with the output of dput(head(df, 20)).
    – Rui Barradas
    Dec 27 '18 at 15:50










  • Thanks Rui. The data is read from a file and I cannot recreate it using simple code. Since I am using bit64 package, some integers are read as integer64 and these are the integers that get deformed. It looks like the matrix does not allow integer64 data type. Or it has to do with the object size limit in the memory or something.
    – Joseph Amram
    Dec 27 '18 at 16:16










  • reproducible example: library(bit64); dd <- data.frame(x=as.integer64("10978645435")); as.matrix(dd)
    – Ben Bolker
    Dec 27 '18 at 16:21










  • Thanks Ben. You got it. I was not aware of how to specify integer64 for a data entry. Thanks again.
    – Joseph Amram
    Dec 27 '18 at 16:24
















0















This question already has an answer here:




  • How to convert a data frame of integer64 values to be a matrix?

    1 answer





  1. I have a data frame (1 x 30 in dimensions) made entirely of numeric columns (double and integer columns). Some of the integers are 10^12.

  2. When I convert the data frame to a matrix using as.matrix() function of base R, something strange happens, an integer like, for example here, 10978645435 would not stay the same in the new object (numeric matrix) but it becomes 5.076377571e-314

  3. I am aware of similar post on the site in which the user had encountered a similar problem but the answer to that post was about coercing column by column to integer64. This approach assumes that I know exactly my columns data type in advance. The answer is not robust at all or dynamic enough with all due respect.


Any idea why would this happen and how I could possibly fix the issue? Thanks in advance.










share|improve this question















marked as duplicate by Bill the Lizard, Hong Ooi, Ben Bolker r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 16:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 2




    Can you post sample data in dput format? Please edit the question with the output of dput(df). Or, if it is too big with the output of dput(head(df, 20)).
    – Rui Barradas
    Dec 27 '18 at 15:50










  • Thanks Rui. The data is read from a file and I cannot recreate it using simple code. Since I am using bit64 package, some integers are read as integer64 and these are the integers that get deformed. It looks like the matrix does not allow integer64 data type. Or it has to do with the object size limit in the memory or something.
    – Joseph Amram
    Dec 27 '18 at 16:16










  • reproducible example: library(bit64); dd <- data.frame(x=as.integer64("10978645435")); as.matrix(dd)
    – Ben Bolker
    Dec 27 '18 at 16:21










  • Thanks Ben. You got it. I was not aware of how to specify integer64 for a data entry. Thanks again.
    – Joseph Amram
    Dec 27 '18 at 16:24














0












0








0








This question already has an answer here:




  • How to convert a data frame of integer64 values to be a matrix?

    1 answer





  1. I have a data frame (1 x 30 in dimensions) made entirely of numeric columns (double and integer columns). Some of the integers are 10^12.

  2. When I convert the data frame to a matrix using as.matrix() function of base R, something strange happens, an integer like, for example here, 10978645435 would not stay the same in the new object (numeric matrix) but it becomes 5.076377571e-314

  3. I am aware of similar post on the site in which the user had encountered a similar problem but the answer to that post was about coercing column by column to integer64. This approach assumes that I know exactly my columns data type in advance. The answer is not robust at all or dynamic enough with all due respect.


Any idea why would this happen and how I could possibly fix the issue? Thanks in advance.










share|improve this question
















This question already has an answer here:




  • How to convert a data frame of integer64 values to be a matrix?

    1 answer





  1. I have a data frame (1 x 30 in dimensions) made entirely of numeric columns (double and integer columns). Some of the integers are 10^12.

  2. When I convert the data frame to a matrix using as.matrix() function of base R, something strange happens, an integer like, for example here, 10978645435 would not stay the same in the new object (numeric matrix) but it becomes 5.076377571e-314

  3. I am aware of similar post on the site in which the user had encountered a similar problem but the answer to that post was about coercing column by column to integer64. This approach assumes that I know exactly my columns data type in advance. The answer is not robust at all or dynamic enough with all due respect.


Any idea why would this happen and how I could possibly fix the issue? Thanks in advance.





This question already has an answer here:




  • How to convert a data frame of integer64 values to be a matrix?

    1 answer








r dataframe matrix long-integer biginteger






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 16:46

























asked Dec 27 '18 at 15:48









Joseph Amram

54




54




marked as duplicate by Bill the Lizard, Hong Ooi, Ben Bolker r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 16:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Bill the Lizard, Hong Ooi, Ben Bolker r
Users with the  r badge can single-handedly close r questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 27 '18 at 16:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 2




    Can you post sample data in dput format? Please edit the question with the output of dput(df). Or, if it is too big with the output of dput(head(df, 20)).
    – Rui Barradas
    Dec 27 '18 at 15:50










  • Thanks Rui. The data is read from a file and I cannot recreate it using simple code. Since I am using bit64 package, some integers are read as integer64 and these are the integers that get deformed. It looks like the matrix does not allow integer64 data type. Or it has to do with the object size limit in the memory or something.
    – Joseph Amram
    Dec 27 '18 at 16:16










  • reproducible example: library(bit64); dd <- data.frame(x=as.integer64("10978645435")); as.matrix(dd)
    – Ben Bolker
    Dec 27 '18 at 16:21










  • Thanks Ben. You got it. I was not aware of how to specify integer64 for a data entry. Thanks again.
    – Joseph Amram
    Dec 27 '18 at 16:24














  • 2




    Can you post sample data in dput format? Please edit the question with the output of dput(df). Or, if it is too big with the output of dput(head(df, 20)).
    – Rui Barradas
    Dec 27 '18 at 15:50










  • Thanks Rui. The data is read from a file and I cannot recreate it using simple code. Since I am using bit64 package, some integers are read as integer64 and these are the integers that get deformed. It looks like the matrix does not allow integer64 data type. Or it has to do with the object size limit in the memory or something.
    – Joseph Amram
    Dec 27 '18 at 16:16










  • reproducible example: library(bit64); dd <- data.frame(x=as.integer64("10978645435")); as.matrix(dd)
    – Ben Bolker
    Dec 27 '18 at 16:21










  • Thanks Ben. You got it. I was not aware of how to specify integer64 for a data entry. Thanks again.
    – Joseph Amram
    Dec 27 '18 at 16:24








2




2




Can you post sample data in dput format? Please edit the question with the output of dput(df). Or, if it is too big with the output of dput(head(df, 20)).
– Rui Barradas
Dec 27 '18 at 15:50




Can you post sample data in dput format? Please edit the question with the output of dput(df). Or, if it is too big with the output of dput(head(df, 20)).
– Rui Barradas
Dec 27 '18 at 15:50












Thanks Rui. The data is read from a file and I cannot recreate it using simple code. Since I am using bit64 package, some integers are read as integer64 and these are the integers that get deformed. It looks like the matrix does not allow integer64 data type. Or it has to do with the object size limit in the memory or something.
– Joseph Amram
Dec 27 '18 at 16:16




Thanks Rui. The data is read from a file and I cannot recreate it using simple code. Since I am using bit64 package, some integers are read as integer64 and these are the integers that get deformed. It looks like the matrix does not allow integer64 data type. Or it has to do with the object size limit in the memory or something.
– Joseph Amram
Dec 27 '18 at 16:16












reproducible example: library(bit64); dd <- data.frame(x=as.integer64("10978645435")); as.matrix(dd)
– Ben Bolker
Dec 27 '18 at 16:21




reproducible example: library(bit64); dd <- data.frame(x=as.integer64("10978645435")); as.matrix(dd)
– Ben Bolker
Dec 27 '18 at 16:21












Thanks Ben. You got it. I was not aware of how to specify integer64 for a data entry. Thanks again.
– Joseph Amram
Dec 27 '18 at 16:24




Thanks Ben. You got it. I was not aware of how to specify integer64 for a data entry. Thanks again.
– Joseph Amram
Dec 27 '18 at 16:24












1 Answer
1






active

oldest

votes


















0














Hi maybe you should take a look to Why are values changing when converting from data.frame to a numeric matrix?



Look at Alex A.'s answer and tell me if it is helping you. I also think it is because the numeric values in your data frame are being treated as factors.



Alex A.'s code : y <- apply(as.matrix(x[, 1:5]), 2, as.numeric)



Edit : Nevermind seems like you have found your problem.






share|improve this answer





















  • Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
    – Joseph Amram
    Dec 27 '18 at 16:18










  • @JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
    – Gainz
    Dec 27 '18 at 16:19










  • But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
    – Joseph Amram
    Dec 27 '18 at 16:39


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Hi maybe you should take a look to Why are values changing when converting from data.frame to a numeric matrix?



Look at Alex A.'s answer and tell me if it is helping you. I also think it is because the numeric values in your data frame are being treated as factors.



Alex A.'s code : y <- apply(as.matrix(x[, 1:5]), 2, as.numeric)



Edit : Nevermind seems like you have found your problem.






share|improve this answer





















  • Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
    – Joseph Amram
    Dec 27 '18 at 16:18










  • @JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
    – Gainz
    Dec 27 '18 at 16:19










  • But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
    – Joseph Amram
    Dec 27 '18 at 16:39
















0














Hi maybe you should take a look to Why are values changing when converting from data.frame to a numeric matrix?



Look at Alex A.'s answer and tell me if it is helping you. I also think it is because the numeric values in your data frame are being treated as factors.



Alex A.'s code : y <- apply(as.matrix(x[, 1:5]), 2, as.numeric)



Edit : Nevermind seems like you have found your problem.






share|improve this answer





















  • Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
    – Joseph Amram
    Dec 27 '18 at 16:18










  • @JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
    – Gainz
    Dec 27 '18 at 16:19










  • But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
    – Joseph Amram
    Dec 27 '18 at 16:39














0












0








0






Hi maybe you should take a look to Why are values changing when converting from data.frame to a numeric matrix?



Look at Alex A.'s answer and tell me if it is helping you. I also think it is because the numeric values in your data frame are being treated as factors.



Alex A.'s code : y <- apply(as.matrix(x[, 1:5]), 2, as.numeric)



Edit : Nevermind seems like you have found your problem.






share|improve this answer












Hi maybe you should take a look to Why are values changing when converting from data.frame to a numeric matrix?



Look at Alex A.'s answer and tell me if it is helping you. I also think it is because the numeric values in your data frame are being treated as factors.



Alex A.'s code : y <- apply(as.matrix(x[, 1:5]), 2, as.numeric)



Edit : Nevermind seems like you have found your problem.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 27 '18 at 16:16









Gainz

345




345












  • Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
    – Joseph Amram
    Dec 27 '18 at 16:18










  • @JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
    – Gainz
    Dec 27 '18 at 16:19










  • But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
    – Joseph Amram
    Dec 27 '18 at 16:39


















  • Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
    – Joseph Amram
    Dec 27 '18 at 16:18










  • @JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
    – Gainz
    Dec 27 '18 at 16:19










  • But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
    – Joseph Amram
    Dec 27 '18 at 16:39
















Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
– Joseph Amram
Dec 27 '18 at 16:18




Thanks Gainz. All data in the data frame is treated as int, integer64, or numeric.
– Joseph Amram
Dec 27 '18 at 16:18












@JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
– Gainz
Dec 27 '18 at 16:19




@JosephAmram Seems related to your question? stackoverflow.com/questions/28262301/…
– Gainz
Dec 27 '18 at 16:19












But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
– Joseph Amram
Dec 27 '18 at 16:39




But that post does not show how to fix it in the conversion process. It tackles the issue if you are creating data object not if you are converting from an object not knowing in advance what your data types are.
– Joseph Amram
Dec 27 '18 at 16:39



Popular posts from this blog

generate and download xml file after input submit (php and mysql) - JPK

Angular Downloading a file using contenturl with Basic Authentication

Can't read property showImagePicker of undefined in react native iOS