[R] time series with quality codes

2007-08-16 Thread Felix Andrews
list(...),

I am working with environmental time series (eg rainfall, stream flow)
that have attached quality codes for each data point. The quality
codes have just a few factor levels, like good, suspect, poor,
imputed. I use the quality codes in plots and summaries. They are
carried through when a time series is aggregated to a longer
time-step, according to rules like worst, median or mode.

I need to support time steps of anything from hours to years. I can
assume the data are regular time series -- they might be irregular
initially but could be 'regularized'. But I would want to plot
irregular time series along with regular ones.

So far I have been using a data frame with a POSIXct column, a numeric
column and a factor column. However I would like to use zoo instead,
because of its many utility functions and easy conversion to ts. Is
there any prospect of zoo handling such numeric + factor data? Other
suggestions on elegant ways to do it are also welcome.

Felix

-- 
Felix Andrews / 安福立
PhD candidate
Integrated Catchment Assessment and Management Centre
The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
http://www.neurofractal.org/felix/
xmpp:[EMAIL PROTECTED]
3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8

__
R-help@stat.math.ethz.ch 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.


Re: [R] time series with quality codes

2007-08-16 Thread Achim Zeileis

On Thu, 16 Aug 2007, Felix Andrews wrote:


list(...),

I am working with environmental time series (eg rainfall, stream flow)
that have attached quality codes for each data point. The quality
codes have just a few factor levels, like good, suspect, poor,
imputed. I use the quality codes in plots and summaries. They are
carried through when a time series is aggregated to a longer
time-step, according to rules like worst, median or mode.

I need to support time steps of anything from hours to years. I can
assume the data are regular time series -- they might be irregular
initially but could be 'regularized'. But I would want to plot
irregular time series along with regular ones.

So far I have been using a data frame with a POSIXct column, a numeric
column and a factor column. However I would like to use zoo instead,
because of its many utility functions and easy conversion to ts. Is
there any prospect of zoo handling such numeric + factor data? Other
suggestions on elegant ways to do it are also welcome.


There is some limited support for this in zoo. You can do
  z - zoo(myfactor, myindex)
and work with it like a zoo series and then
  coredata(z)
will recover a factor. However, you cannot bind this to other series 
without losing the factor structure. At least not in a plain zoo series. 
But you can do

  df - merge(z, Z, retclass = data.frame)
where every column of the resulting data.frame is a univariate zoo series.

The final option would be to just have a data.frame as usual and put your 
data/index into one column. But then it's more difficult to leverage zoo's 
functionality.


I would like to have more support for things like this, but currently this 
is what we have.


Best,
Z


Felix

--
Felix Andrews / 安福立
PhD candidate
Integrated Catchment Assessment and Management Centre
The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
http://www.neurofractal.org/felix/
xmpp:[EMAIL PROTECTED]
3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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.


Re: [R] time series with quality codes

2007-08-16 Thread Gabor Grothendieck
In addition, we could create a function to.df which converts a zoo
object to a data frame assuming that any column that only contains
1:nlevels is a factor with the indicated level names.  Use to.df just
before plotting:

library(zoo)
set.seed(1)
f - zoo(factor(sample(3, 10, replace = TRUE)))
x - zoo(rnorm(10))
y - zoo(rnorm(10))
z - merge(x, y, f)

to.df - function(z, levels = letters[1:3], time = FALSE) {
zz - as.data.frame(z)
for(i in ncol(zz))
if (all(zz[,i] %in% seq_along(levels)))
z[,i] - factor(levels[z[,i]])
if (time) cbind(index = index(z), zz) else zz
}

library(lattice)
xyplot(y ~ x | f, data = to.df(z))




On 8/16/07, Achim Zeileis [EMAIL PROTECTED] wrote:
 On Thu, 16 Aug 2007, Felix Andrews wrote:

  list(...),
 
  I am working with environmental time series (eg rainfall, stream flow)
  that have attached quality codes for each data point. The quality
  codes have just a few factor levels, like good, suspect, poor,
  imputed. I use the quality codes in plots and summaries. They are
  carried through when a time series is aggregated to a longer
  time-step, according to rules like worst, median or mode.
 
  I need to support time steps of anything from hours to years. I can
  assume the data are regular time series -- they might be irregular
  initially but could be 'regularized'. But I would want to plot
  irregular time series along with regular ones.
 
  So far I have been using a data frame with a POSIXct column, a numeric
  column and a factor column. However I would like to use zoo instead,
  because of its many utility functions and easy conversion to ts. Is
  there any prospect of zoo handling such numeric + factor data? Other
  suggestions on elegant ways to do it are also welcome.

 There is some limited support for this in zoo. You can do
   z - zoo(myfactor, myindex)
 and work with it like a zoo series and then
   coredata(z)
 will recover a factor. However, you cannot bind this to other series
 without losing the factor structure. At least not in a plain zoo series.
 But you can do
   df - merge(z, Z, retclass = data.frame)
 where every column of the resulting data.frame is a univariate zoo series.

 The final option would be to just have a data.frame as usual and put your
 data/index into one column. But then it's more difficult to leverage zoo's
 functionality.

 I would like to have more support for things like this, but currently this
 is what we have.

 Best,
 Z

  Felix
 
  --
  Felix Andrews / ��
  PhD candidate
  Integrated Catchment Assessment and Management Centre
  The Fenner School of Environment and Society
  The Australian National University (Building 48A), ACT 0200
  Beijing Bag, Locked Bag 40, Kingston ACT 2604
  http://www.neurofractal.org/felix/
  xmpp:[EMAIL PROTECTED]
  3358 543D AAC6 22C2 D336  80D9 360B 72DD 3E4C F5D8
 
  __
  R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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.