Remove the for loop and all the [i]'s in your code and it will probably go
faster. I.e., change
f0 <- function (lines)
{
numbers <- vector("numeric")
for (i in 1:length(lines)) {
lines[i] <- sub("[^ ]+ +", "", lines[i])
lines[i] <- gsub(" ", "", lines[i])
numbers <
> peter dalgaard
> on Fri, 8 Sep 2017 16:12:21 +0200 writes:
>> On 8 Sep 2017, at 15:51 , Martin Møller Skarbiniks
>> Pedersen wrote:
>>
>> On 8 September 2017 at 14:37, peter dalgaard
>> wrote:
>>>
>>>
On 8 Sep 2017, at 14:03 , peter dalgaard
> On 8 Sep 2017, at 15:51 , Martin Møller Skarbiniks Pedersen
> wrote:
>
> On 8 September 2017 at 14:37, peter dalgaard wrote:
>>
>>
>>> On 8 Sep 2017, at 14:03 , peter dalgaard wrote:
>>>
>>> x <- scan("~/Downloads/digits.txt")
>>> x <- x[-seq(1,22,11)]
>>
>> ...and, come to think of
On 8 September 2017 at 14:37, peter dalgaard wrote:
>
>
> > On 8 Sep 2017, at 14:03 , peter dalgaard wrote:
> >
> > x <- scan("~/Downloads/digits.txt")
> > x <- x[-seq(1,22,11)]
>
> ...and, come to think of it, if you really want the 100 random digits:
>
> xx <- c(outer(x,10^(0:4), "%/%")
> On 8 Sep 2017, at 14:03 , peter dalgaard wrote:
>
> x <- scan("~/Downloads/digits.txt")
> x <- x[-seq(1,22,11)]
...and, come to think of it, if you really want the 100 random digits:
xx <- c(outer(x,10^(0:4), "%/%")) %% 10
--
Peter Dalgaard, Professor,
Center for Statistics, Copen
Hi
see in line
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin
> Moller Skarbiniks Pedersen
> Sent: Friday, September 8, 2017 11:58 AM
> To: r-help@r-project.org
> Subject: Re: [R] Optimize code to read text-file wi
Simplest version that I can think of:
x <- scan("~/Downloads/digits.txt")
x <- x[-seq(1,22,11)]
length(x) # 20
hist(x)
Now, because it's Friday:
How does one work out the theoretical distribution of the following table?
> table(table(factor(x,levels=0:9)))
0 1 2 3
On 8 September 2017 at 11:25, PIKAL Petr wrote:
> > Moller Skarbiniks Pedersen
> My program which is slow looks like this:
> >
> > filename <- "digits.txt"
> > lines <- readLines(filename)
>
> why you do not read a file as a whole e.g. by
>
> lines<-read.table("digits.txt")
>
Good idea.
>
> An
Hi
see in line
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Martin
> Moller Skarbiniks Pedersen
> Sent: Friday, September 8, 2017 10:49 AM
> To: r-help@r-project.org
> Subject: [R] Optimize code to read text-file with digits
&
Hi,
Every day I try to write some small R programs to improve my R-skills.
Yesterday I wrote a small program to read the digits from "A Million
Random Digits" from RAND.
My code works but it is very slow and I guess the code is not optimal.
The digits.txt file downloaded from
https://www.ra
10 matches
Mail list logo