[R] how to apply the same function to multiple data set

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Wed Jun 27 14:20:16 CEST 2012


try this:

sapply(estIID50, "[[", 'para')


Best,
Dimitris


On 6/27/2012 2:17 PM, Al Ehan wrote:
> Sorry, one more simple question. how do I pick, from the generated
> lapply, the $para for each X. say here I have 2 generated list from
> previous function. how do I take only the $para for each X?
>
> Thank you so much for your kindness.
>
> $X1
> $X1$type
> [1] "gev"
>
> $X1$para
>           xi       alpha       kappa
> 896.6893825 143.0511714  -0.5062221
>
> $X1$source
> [1] "pargev"
>
>
> $X2
> $X2$type
> [1] "gev"
>
> $X2$para
>           xi       alpha       kappa
> 955.6826879 160.1111226  -0.2974729
>
> $X2$source
> [1] "pargev"
>
>
> Best,
> Al
>
> On Wed, Jun 27, 2012 at 12:45 PM, Dimitris Rizopoulos
> <d.rizopoulos at erasmusmc.nl <mailto:d.rizopoulos at erasmusmc.nl>> wrote:
>
>     you will have to check what function pargev() returns as a result. I
>     would guess that is probably a list. In any case, you could use
>     something like the following:
>
>     estIID50 <- lapply(IID50, function (m)  pargev(lmom.ub(m)))
>
>     I hope it helps.
>
>     Best,
>     Dimitris
>
>
>
>     On 6/27/2012 1:31 PM, Al Ehan wrote:
>
>         Hi R-users,
>
>         I'm trying to repeat the same procedure to 1000 data set. I know
>         this is
>         very easy, but I got stuck finding the right and fastest way in
>         running it.
>
>         IID50=Riidf[1:50,1:1000] #where IID50 is a dataframe consist of
>         1000 time
>         series(as column) and 50 time scales (row).
>
>         #what I tried to do:
>
>         estIID50=rep(NA,1000)
>         for (i in 1:1000)
>         estIID50[i]=pargev(lmom.ub(__IID50[1:50,i]))
>
>         #warning message
>           In estIID50[i] = pargev(lmom.ub(IID50[1:50, i])) :
>            number of items to replace is not a multiple of replacement
>         length
>
>         #pargev is a function from lmomco package. I would like to apply
>         it to the
>         1000 set of time series that I have in the IID50, without having
>         to do it
>         manually.
>         #I dont understand what is the warning warns about
>
>         Can somebody help me?
>
>                 [[alternative HTML version deleted]]
>
>         ________________________________________________
>         R-help at r-project.org <mailto:R-help at r-project.org> mailing list
>         https://stat.ethz.ch/mailman/__listinfo/r-help
>         <https://stat.ethz.ch/mailman/listinfo/r-help>
>         PLEASE do read the posting guide
>         http://www.R-project.org/__posting-guide.html
>         <http://www.R-project.org/posting-guide.html>
>         and provide commented, minimal, self-contained, reproducible code.
>
>
>     --
>     Dimitris Rizopoulos
>     Assistant Professor
>     Department of Biostatistics
>     Erasmus University Medical Center
>
>     Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
>     Tel: +31/(0)10/7043478 <tel:%2B31%2F%280%2910%2F7043478>
>     Fax: +31/(0)10/7043014 <tel:%2B31%2F%280%2910%2F7043014>
>     Web: http://www.erasmusmc.nl/__biostatistiek/
>     <http://www.erasmusmc.nl/biostatistiek/>
>
>
>

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/



More information about the R-help mailing list