Message-ID: <CAGAA5be70Rn9BAhoU7snE70a6ihDWaa=vr5eT4Rag9nBOroa4w@mail.gmail.com>
Date: 2017-09-08T13:51:21Z
From: Martin Møller Skarbiniks Pedersen
Subject: Optimize code to read text-file with digits
In-Reply-To: <F562C80A-2224-43B7-AFC8-92618A03FCEF@gmail.com>
On 8 September 2017 at 14:37, peter dalgaard <pdalgd at gmail.com> wrote:
>
>
> > On 8 Sep 2017, at 14:03 , peter dalgaard <pdalgd at gmail.com> wrote:
> >
> > x <- scan("~/Downloads/digits.txt")
> > x <- x[-seq(1,220000,11)]
>
> ...and, come to think of it, if you really want the 1000000 random digits:
>
> xx <- c(outer(x,10^(0:4), "%/%")) %% 10
>
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
[[alternative HTML version deleted]]