0

I have a great data.matrix and I want to calculate the sum of the rows. Using rowSums function results in Inf values for sum because (presumably) the numbers are too large.

So I tried using Brobdingnagian numbers (from Brobdingnagian package, function as.brob) to deal with great numbers. But that is not working. Here is an example of what I have done with mtcars example dataset

library(dplyr)
library(brobdingnag)
mtcars <- data.matrix(mtcars)
mtcars.rowsum <- mtcars %>% as.brob(.) %>% rowSums(.)

Error in h(simpleError(msg, call)) : 
  Error argument 'x' during method selection for function 'rowSums': 
invalid class “brob” object: invalid object for slot "positive" in class "brob": 
got class "matrix", should be or extend class "logical"

Selecting TRUE or FALSE in brob(.,positive = ) results in an error unused argument.

How to handle great numbers for rowSums() in R? How to use as.brob in a data.matrix?

JORIS
  • 59
  • 7
  • Why do you assume `as.brob` can handle a matrix as input? Why do you assume, `rowSums` can handle input of class "brob"? – Roland Jan 26 '21 at 16:31
  • 1
    Why don't you scale the matrix by dividing it by a Big Number, `data.matrix2 <- data.matrix / 100000000`, then `rowSums` the scaled matrix and work with the scaled sums. – SteveM Jan 26 '21 at 16:41

0 Answers0