-
Notifications
You must be signed in to change notification settings - Fork 25
/
wide.to.long.Rd
60 lines (44 loc) · 1.63 KB
/
wide.to.long.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
\name{wide.to.long}
\alias{WideToLong}
\alias{LongToWide}
\Rdversion{1.1}
\title{
Convert Between Wide and Long Format
}
\description{
Convert a multivariate time series between wide and long formats. In
"wide" format there is one row per time point, with series organzied
by columns. In "long" format there is one row per observation, with
variables indicating the series and time point to which an observation
belongs.
}
\usage{
WideToLong(response, na.rm = TRUE)
LongToWide(response, series.id, timestamps)
}
\arguments{
\item{response}{For \code{WideToLong} this is a matrix, with rows
representing time and columns representing variables. This can be a
\code{\link{zoo}} matrix with timestamps as an index.
For \code{LongToWide}, \code{response} is a vector.}
\item{na.rm}{If TRUE then missing values will be omitted from the
returned data frame (their absence denoting missingness).
Otherwise, missing values will be included as NA's.}
\item{series.id}{A factor (or variable coercible to factor) of the
same length as \code{response}, indicating the series to which each
observation belongs. }
\item{timestamps}{A variable of the same length as \code{response},
indicating the time period to which each observation belongs.}
}
\value{
\code{LongToWide} returns a zoo matrix with the time series in wide format.
\code{WideToLong} returns a 3-column data frame with columns "time", "series", and "values".
}
\author{
Steven L. Scott \email{[email protected]}
}
\examples{
data(gdp)
gdp.wide <- LongToWide(gdp$GDP, gdp$Country, gdp$Time)
gdp.long <- WideToLong(gdp.wide)
}