Quantcast

how to apply the same function to multiple data set

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

how to apply the same function to multiple data set

Balqis
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to apply the same function to multiple data set

D. Rizopoulos
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]]
>
> ______________________________________________
> [hidden email] 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.
>

--
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/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to apply the same function to multiple data set

Rui Barradas
In reply to this post by Balqis
Hello,

Try the following.

estIID50 <- apply( IID50, 2, function(x) pargev(lmom.ub(x)) )

And see ?apply

Hope this helps,

Rui Barradas

Em 27-06-2012 12:31, Al Ehan escreveu:

> 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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to apply the same function to multiple data set

Balqis
In reply to this post by D. Rizopoulos
It's working!!!! I am excited than ever!!
Thank you so much!!!!

On Wed, Jun 27, 2012 at 12:45 PM, Dimitris Rizopoulos <
[hidden email]> 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]]
>>
>> ______________________________**________________
>> [hidden email] 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
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/**biostatistiek/<http://www.erasmusmc.nl/biostatistiek/>
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to apply the same function to multiple data set

Balqis
In reply to this post by D. Rizopoulos
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 <
[hidden email]> 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]]
>>
>> ______________________________**________________
>> [hidden email] 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
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/**biostatistiek/<http://www.erasmusmc.nl/biostatistiek/>
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: how to apply the same function to multiple data set

D. Rizopoulos
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
> <[hidden email] <mailto:[hidden email]>> 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]]
>
>         ________________________________________________
>         [hidden email] <mailto:[hidden email]> 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/

______________________________________________
[hidden email] 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.
Loading...