Skip to content
Prev 371279 / 398530 Next

Optimize code to read text-file with digits

On 8 September 2017 at 14:37, peter dalgaard <pdalgd at gmail.com> wrote:
Hi Peter,
  Thanks a lot for the answers. I can see that I need to read about outer().
  However I get a different result than expected.

R> x <- scan("digits.txt")
Read 220000 items

R> head(x)
[1]     0 10097 32533 76520 13586 34673

R> x <- x[-seq(1,220000,11)]
R> head(x)
[1] 10097 32533 76520 13586 34673 54876

R> head(c(outer(x,10^(0:4), "%/%")) %% 10, 10) #
[1] 7 3 0 6 3 6  9 7 2 5

Regards
Martin