[R] do not perform function if the outcome is NA

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Jul 24 04:25:00 CEST 2013


The problem specification here seems flawed. The normal return values are unitless, but the abnormal return values have units. I would expect that returning NA when the standard deviations are zero will give rather less surprising results.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

"iza.ch1" <iza.ch1 at op.pl> wrote:
>Hi Rui 
>
>Thanks a lot. It works perfect. 
>
>Izzie
>
>
>> Hello,
>> 
>> Try the following.
>> 
>> 
>> standardised.abnormal.returns <- 
>> lapply(seq_len(ncol(abnormal.returns)),function(i) {
>> 	if(standard.deviation[i,1] == 0)
>> 		abnormal.returns[,i]
>> 	else
>> 		abnormal.returns[,i]/standard.deviation[i,1]
>> })
>> 
>> 
>> 
>> Hope this helps,
>> 
>> Rui Barradas
>> 
>> Em 23-07-2013 22:58, iza.ch1 escreveu:
>> > Hi you all
>> >
>> > I have a question regarding the function. In my function I divide
>the values by the standard errors and sometimes the standard error is
>equal to zero and I get the result NA. Can I write the function in the
>way that if the outcome of the function is zero then the function is
>not conducted and it stays the value (not divided by standard errors)?
>the code for my function is the following:
>> >
>> >
>standardised.abnormal.returns<-lapply(seq_len(ncol(abnormal.returns)),function(i)
>{abnormal.returns[,i]/standard.deviation[i,1]})
>> >
>> > Thank you all for the help
>> >
>> > ______________________________________________
>> > R-help at r-project.org 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.
>> >
>> 
>______________________________________________
>R-help at r-project.org 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.



More information about the R-help mailing list