Hello. Trying to create a number by stringing together the digits "146" 841 times, then convert it into a numeric variable so that I can check its remainder when dividing by 11.
However, when I try to coefrce the string into a different type, I either get this error warning:
make_huge <- function(digits,repeats) {
paste(rep(digits,repeats), collapse = "")
}
integer_huge <- as.numeric(make_huge)
"Error in as.numeric(make_huge) :
cannot coerce type 'closure' to vector of type 'double' "
or this one:
integer_huge <- as.integer(make_huge)
"Warning message:
NAs introduced by coercion to integer range "
Any idea how I can fix this? Or an entirely different approach to generating a huge number without having to type it and then be able to do arithmetic functions on it?
R (like almost all programs) uses 32-bit integers, which means the largest integer is 2,147,483,647 ( 2^31 - 1 ). So use of as.integer() is doomed.
The first error message is because you applied as.numeric() to make_huge (a function definition), which makes no sense. You could try as.numeric(make_huge("146", 841)), but that will just produce Inf as the result.
Your best bet is to use a loop, where in each pass you take the result of the previous pass (an integer from 0 to 10), multiply it by 1000 and add 146, get the remainder mod 11, and move on to the next pass.
Yes, thank you. It was a bad copy and paste job. I meant to apply as.integerto the function output, which I thought I had stored as make_huge. Instead, in this version of the code I had used that as the function definition.
Ah, excellent. This was actually a bad copy and paste. Elsewhere in a later chunk of code I didn't include, I had saved the output of that function as make_huge. I had pasted the error codes from a few different places.
I wasn't sure how to how to perform the operations on an object I hadn't actually defined outside of the function. Thank you!