[R] Getting Rid of NaN in ts Object

Lorenzo Isella lorenzo.isella at gmail.com
Fri May 27 13:51:08 CEST 2016


Perfect!
Exactly what I was looking for.
Thanks

Lorenzo

On Fri, May 27, 2016 at 01:50:03PM +0200, Christian Brandstätter wrote:
>Hi Lorenzo,
>
>Try:
>
>tt[is.nan(tt)] <- NA
>tt <- na.omit(tt)
>
>Best,
>
>Christian
>
>
>Am 27.05.2016 um 13:38 schrieb Lorenzo Isella:
>>On Fri, May 27, 2016 at 08:46:20PM +1000, Jim Lemon wrote:
>>>Hi Lorenzo,
>>>Maybe:
>>>
>>>tt<-tt[!is.nan(tt)]
>>>
>>>Jim
>>
>>
>>Not really.
>>
>>>tt<-structure(c(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
>>+ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 1133.09, 1155.77, 1179.12,
>>+ 1182.85, 1133.43, 1103.36, 1081.19, 1058.55, 1056.95, 1059.13,
>>+ 1018.18, 920.62, 865.99, 856.29, 841.58, 857.7, 852.71, 890.76
>>+ ), .Tsp = c(1980, 2015, 1), class = "ts")
>>>
>>>tt2<-tt[!is.nan(tt)]
>>>class(tt)
>>[1] "ts"
>>>class(tt2)
>>[1] "numeric"
>>
>>
>>and I lose all the info about the years.
>>
>>Lorenzo
>>
>>
>>
>>
>>
>>
>>
>>>
>>>
>>>On Fri, May 27, 2016 at 8:14 PM, Lorenzo Isella
>>><lorenzo.isella at gmail.com> wrote:
>>>>Dear All,
>>>>I am sure the answer is a one liner, but I am banging my head against
>>>>the wall and googling here and there has not helped much.
>>>>Consider the following time series
>>>>
>>>>tt<-structure(c(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN,
>>>>NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, 1133.09, 1155.77, 1179.12,
>>>>1182.85, 1133.43, 1103.36, 1081.19, 1058.55, 1056.95, 1059.13,
>>>>1018.18, 920.62, 865.99, 856.29, 841.58, 857.7, 852.71, 890.76
>>>>), .Tsp = c(1980, 2015, 1), class = "ts")
>>>>
>>>>
>>>>where the NaN do *not* occur internally. How can I automatically get
>>>>rid of them and adjust the start and end year of the time series
>>>>accordingly?
>>>>Many thanks
>>>>
>>>>Lorenzo
>>>>
>>>>______________________________________________
>>>>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.
>>
>>______________________________________________
>>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