Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

largenumber - large rowSums() results in Inf ? large number problem in R

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?

question from:https://stackoverflow.com/questions/65905047/large-rowsums-results-in-inf-large-number-problem-in-r

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...