Re: [R] Alternatives to unlist()

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 04 May 2007 18:56:12 +0100 (BST)

First, your example works happily in a 1Gb Windows machine under R 2.5.0: your R (2.2.1) is well overdue for an update.

What you are generating is a random number of rexp(rate=10) random variables. So all you need is

n <- 1000000
N <- sum (rpois(n, 26))
vv <- rexp(N, 10)
mean(vv[vv < 0.1])

which runs is ca 500Mb and 6 secs.

On Fri, 4 May 2007, Jacques Wagnor wrote:

> Given the following, one of the things I am trying to see is what % of
> draws are below a certain number:
>
> lambda <- 3
> rate <- 5
> n <- 5
>
> set.seed(123)
> v <- replicate(n, rexp(rpois(1,lambda), rate))
> vv <- unlist(v)
> cat("% of draws below 0.1:", round(length(subset(vv, vv <
> 0.1))/length(vv)*100,0), "%\n")
>
> In actuality, my lambda, rate, and n are 26, 10, 1000000,
> respectively; which in effect makes the length of vv roughly equal
> 26'000'000.
> When I run cat(...), I get the following:
>
> Error: cannot allocate vector of size 101540 Kb
> In addition: Warning messages:
> 1: Reached total allocation of 1015Mb: see help(memory.size)
> 2: Reached total allocation of 1015Mb: see help(memory.size)
>
> Rather than keep the code as is and resort to memory.limit(), I would
> like to see how the code can be modified (i.e., alternatives to
> unlist()) such that I could still see what % of draws are below a
> certain number.
>
> I'd appreciate any suggestions.
>
> Regards,
>
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 2.1
> year 2005
> month 12
> day 20
> svn rev 36812
> language R
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 04 May 2007 - 18:05:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 04 May 2007 - 18:31:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.