1

I was trying to produce some code for R to see just how random the distribution of digits in pi was and I'm limited to only being able to take in 10,000 places because of the way I read in the variable as a string and then try to chop it up into a vector. Can this be easily circumnavigated to allow me to use more digits for input or will I have to resort to creating loops and multiple vectors to contain more digits?

Here's the code:

fileName <- 'pi-billion.txt'
piStr = readChar(fileName, file.info(fileName)$size)
piValue = as.numeric(strsplit(as.character(piStr), "")[[1]])

digitcheck = matrix(0, nrow=10, ncol=10)

for(n in 3:9998)
{

if (piValue[n]!=0 & piValue[n+1]!=0){digitcheck[piValue[n],piValue[n+1]] = digitcheck[piValue[n],piValue[n+1]] +1}
else if (piValue[n+1]==0 & piValue[n]!=0){digitcheck[piValue[n],10]=digitcheck[piValue[n],10]+1}
else if (piValue[n+1]!=0 & piValue[n]==0){digitcheck[10,piValue[n+1]]=digitcheck[10,piValue[n+1]]+1}
else {digitcheck[10,10]=digitcheck[10,10]+1}
}

1 Answers1

0

try this readChar(fileName, file.info(fileName)$size)

Qbik
  • 5,885
  • 14
  • 62
  • 93