zoo_tidiers {broom} | R Documentation

## Tidying methods for a zoo object

### Description

Tidies `zoo` (Z's ordered observations) time series objects. `zoo` objects are not tidy by default because they contain one row for each index and one series per column, rather than one row per observation per series.

### Usage

    ## S3 method for class 'zoo'
    tidy(x, ...)

### Arguments

`x` | An object of class `"zoo"`
`...` | extra arguments (not used)

### Value

`tidy` returns a data frame with one row for each observation in each series, with the following columns:

`index` | Index (usually date) for the zoo object
`series` | Name of the series
`value` | Value of the observation

### Examples

    if (require("zoo", quietly = TRUE)) {
        set.seed(1071)

        # data generated as shown in the zoo vignette
        Z.index <- as.Date(sample(12450:12500, 10))
        Z.data <- matrix(rnorm(30), ncol = 3)
        colnames(Z.data) <- c("Aa", "Bb", "Cc")
        Z <- zoo(Z.data, Z.index)

        tidy(Z)

        if (require("ggplot2", quietly = TRUE)) {
            ggplot(tidy(Z), aes(index, value, color = series)) + geom_line()
            ggplot(tidy(Z), aes(index, value)) + geom_line() +
                facet_wrap(~ series, ncol = 1)

            Zrolled <- rollmean(Z, 5)
            ggplot(tidy(Zrolled), aes(index, value, color = series)) + geom_line()
        }
    }

[Package broom version 0.4.2 Index]