Hello
I have a vector a =(-2,0,0,0,1,0,0,3,0,0,-4)
I want to replace all zeros into previous non-zero state. So for instance the
above vector should be converted into:
a= (-2,-2,-2,-2,1,1,1,3,3,3,-4)
I tried many things and finally concluded that probably(?) rollapply may be the
best way?
I tried
f= function(x){
ifelse(x==0,Lag(x),x)
}
And then, rollappy(a,1,f) and that didn't work. Can someone help please?
Thx
R
Jefferies archives and monitors outgoing and incoming e-mail. The contents of
this email, including any attachments, are confidential to the ordinary user of
the email address to which it was addressed. If you are not the addressee of
this email you may not copy, forward, disclose or otherwise use it or any part
of it in any form whatsoever. Since the confidentiality of Internet e-mail
cannot be guaranteed, please do not include private or confidential information
(such as account numbers) or instructions requiring your authorization (such as
orders or funds transfers) in your e-mail communication to us. This email may
be produced at the request of regulators or in connection with civil
litigation. Jefferies accepts no liability for any errors or omissions arising
as a result of transmission. Although this transmission and any attachments are
believed to be free of any virus or other defect that might affect any computer
system into which it is received and opened, it is the!
responsibility of the recipient to ensure that it is virus free and no
responsibility is accepted by Jefferies, its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use. In the
United Kingdom, Jefferies operates as Jefferies International Limited;
registered in England: no. 1978621; and Jefferies Bache Limited; registered in
England: no. 114226; registered office for both: Vintners Place, 68 Upper
Thames Street, London EC4V 3BJ. Jefferies International Limited and Jefferies
Bache Limited are authorised and regulated by the Financial Services Authority.
If you received this transmission in error, please immediately contact the
sender and destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.