[R] 3d timeseries dataframe
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Aug 23 13:59:50 CEST 2006
Jon Minton wrote:
> Hi,
>
>
>
> I'm new to R so this might be a little basic for enlightened people like
> yourselves...
>
>
>
> I have quarterly British Labour Force Survey (Local Area) data from 1992 to
> present in .tab format* in folders running from 01 (for the first time
> period) to 56 (for the most recent).
>
>
>
> i.e. my directory structure is:
>
> .../t/
>
> 01
>
> ...
>
> 56
>
>
>
> Taking the result of dir() on the t/ directory I can get access to each
> subdirectory as an element in a vector of strings (i.e. element [n] points
> to directory n) Using a regex sequence I can specify only the lad .tab file
> within each directory (as they each contain another .tab datafile for higher
> level geographical regions)
>
>
>
> I now need to load all the data into a 3d dataframe,** where the first
> dimension refers to the t value (01...56), and I can access it to make
> longitudinal comparisons between variables.
>
"dataframe" means a specific 2d layout, like a table in a database. R
has 3d structures, but calls
them "array"s. All entries in an array must be the same type (columns
in a dataframe need not be).
So the basic outline of what you want is something like this:
thedata <- array(NA, c(m, n, p))
where m, n and p are the extents of the 3 indices of the desired array,
e.g. c(56, 7, 5)
if you have 5 daily variables, measured daily over 56 weeks.
Then fill the array by something like this:
for (m in 1:56) {
# read period m
thedata[m, ,] <- some data
}
>
>
> How do I do this?
>
>
>
> Thanks for your help,
>
>
>
> Jon
>
>
>
> * some of the data was only available in other formats: does R read SPSS
> .por (portable) data? If not I'll just convert it.
>
> ** or would it be better to just mark the data from each t with a new
> variable, and have it as a long file?
>
Lots of functions in R are set up to use dataframes rather than arrays
or subsets of arrays, so this might be more convenient.
Duncan Murdoch
>
>
>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list