Hello everyone, I have a time serie of n values, some are na's. I want to get a vector of size n whose elements represent on the time t < n the number of missing values between o and t. I know I can do it with a loop but I wanted to know if there was a function or a special syntax to do this. Thanks a lot! -- View this message in context: http://n4.nabble.com/Counting-Na-values-on-a-time-serie-only-on-the-past-datas-tp1101617p1101617.html Sent from the R help mailing list archive at Nabble.com.
William Dunlap
2010-Jan-22 17:02 UTC
[R] Counting Na values on a time serie only on the past datas
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of anna > Sent: Friday, January 22, 2010 8:56 AM > To: r-help at r-project.org > Subject: [R] Counting Na values on a time serie only on the past datas > > > Hello everyone, I have a time serie of n values, some are > na's. I want to get > a vector of size n whose elements represent on the time t < n > the number of > missing values between o and t. I know I can do it with a > loop but I wanted > to know if there was a function or a special syntax to do > this. Thanks a > lot!If x is your vector of numbers then cumsum(is.na(x)) should give what you want. You didn't show sample data so here is my example > x <- c(101,102,NA,104,NA) > cumsum(is.na(x)) [1] 0 0 1 1 2 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -- > View this message in context: > http://n4.nabble.com/Counting-Na-values-on-a-time-serie-only-on-the-past-datas-tp1101617p1101617.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
William thanks a lot that is exactly what I wanted! :working: -- View this message in context: http://n4.nabble.com/Counting-Na-values-on-a-time-serie-only-on-the-past-datas-tp1101617p1103103.html Sent from the R help mailing list archive at Nabble.com.
Apparently Analagous Threads
- question on assigning an argument in a function that is create by the function itself
- Corregir mismo ID para individuos diferentes en una serie temporal
- Internal NA removal out of Time Series with na.omit.ts()
- Corregir mismo ID para individuos diferentes en una serie temporal
- Using NA as a break point for indicator variable?