[R] creating a list based on various mean values

Michael Hannon jmhannon.ucdavis at gmail.com
Fri Oct 23 11:06:21 CEST 2015


Does the following not do what you want?

k1 <- c(0.005, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900,
        1.000, 1.100, 1.200, 1.300, 1.400, 1.500, 1.600, 1.700, 1.800,
        1.900, 2.000, 5.000, 10.000)
k1

xr <- lapply(k1, rnorm, n=20)
xr


On Fri, Oct 23, 2015 at 1:51 AM, Erin Hodgess <erinm.hodgess at gmail.com> wrote:
> Hello!
>
> I would like to create a list of random values, based on various means.
> Here are the potential mean values:
>
>> k1
>  [1]  0.005  0.200  0.300  0.400  0.500  0.600  0.700  0.800  0.900  1.000
>  1.100  1.200  1.300  1.400
> [15]  1.500  1.600  1.700  1.800  1.900  2.000  5.000 10.000
>
> There are 22 of them.
>
> My original thought was to use "do.call" to produce a list of 22 items of
> size 20.
>
>> xr <- do.call("rnorm",args=list(n=20,mean=k1))
>> xr
>  [1] -1.46443269  0.83384389  0.39176720 -0.17954959  0.28245948
> -0.44148055  1.98009926  1.73881739
>  [9]  1.37312454  1.40509257 -0.03762214  0.43636354  1.82175069
>  1.96439065  2.71731752  1.02388062
> [17]  1.20732047  3.08650964  0.87910868  0.13018727
>>
>
> However, I am just getting back one set of size 20.  What am I doing wrong,
> please? Or do I need to do a loop, please?  I thought that there must be a
> more elegant solution.
>
> This is on a Macbook Air, R version 3.2.2
>
> Thanks so much,
> Sincerely
>
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodgess at gmail.com
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list