example.data.wide <- data.frame(
v = c(35,42),
x1 = c(1.1,2.1),
x2 = c(1.2,2.2),
x3 = c(1.3,2.3),
x4 = c(1.4,2.4),
y1 = c(2.5,3.5),
y2 = c(2.7,3.7),
y3 = c(2.9,3.9))
example.data.wide
# The following two calls are equivalent:
example.data.long <- Reshape(data=example.data.wide,
x=c(x1,x2,x3,x4),
# N.B. it is possible to
# specify 'empty' i.e. missing
# measurements
y=c(y1,y2,y3,),
t=1:4,
direction="long")
example.data.long <- Reshape(data=example.data.wide,
list(
x=c(x1,x2,x3,x4),
# N.B. it is possible to
# specify 'empty' i.e. missing
# measurements
y=c(y1,y2,y3,)
),
t=1:4,
direction="long")
example.data.long
# Since the data frame contains an "reshapeLong" attribute
# an id variable is already specified and part of the data
# frame.
example.data.wide <- Reshape(data=example.data.long,
x=c(x1,x2,x3,x4),
y=c(y1,y2,y3,),
t=1:4,
direction="wide")
example.data.wide
# Here we examine the case where no "reshapeLong" attribute
# is present:
example.data.wide <- Reshape(data=example.data.long,
x=c(x1,x2,x3,x4),
y=c(y1,y2,y3,),
t=1:4,
id=v,
direction="wide")
example.data.wide
# Here, an "automatic" time variable is created. This works
# only if there is a single argument other than the data=
# and direction= arguments
example.data.long <- Reshape(data=example.data.wide,
list(
x=c(x1,x2,x3,x4),
y=c(y1,y2,y3,)
),
direction="long")
example.data.long
example.data.wide <- Reshape(data=example.data.long,
list(
x=c(x1,x2,x3,x4),
y=c(y1,y2,y3,)
),
direction="wide")
example.data.wide
Run the code above in your browser using DataLab