Graphics Reference
In-Depth Information
Discussion
The dcast() function requires you to specify the IDvariables (those that remain in columns)
and the variablevariables (those that get “moved to the top”). This is done with a formula where
the ID variables are before the tilde (~ ) and the variable variables are after it.
In the preceding example, there are two ID variables and one variable variable. In the next one,
there is one ID variable and two variable variables. When there is more than one variable vari-
able, the values are combined with an underscore:
dcast(plum, time ~ length + survival, value.var = "count" )
time long_dead long_alive short_dead short_alive
at_once
84
156
133
107
in_spring
156
84
209
31
See Also
See Converting Data from Wide to Long to do conversions in the other direction, from wide to
long.
See the unstack() function for another way of converting from long to wide.
ConvertingaTimeSeriesObjecttoTimesandValues
Problem
You have a time series object that you wish to convert to numeric vectors representing the time
and values at each time.
Solution
Use the time() function to get the time for each observation, then convert the times and values
to numeric vectors with as.numeric() :
# Look at nhtemp Time Series object
nhtemp
Time Series:
Start = 1912
End = 1971
Frequency = 1
[ 1 ] 49.9 52.3 49.4 51.1 49.4 47.9 49.8 50.9 49.3 51.9 50.8 49.6 49.3 50.6 48.4
[ 16 ] 50.7 50.9 50.6 51.5 52.8 51.8 51.1 49.8 50.2 50.4 51.6 51.8 50.9 48.8 51.7
Search WWH ::




Custom Search