Re: [R] 3d timeseries dataframe

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 23 Aug 2006 - 21:59:50 EST

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@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.
>



R-help@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. Received on Thu Aug 24 08:48:45 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 24 Aug 2006 - 10:22:31 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.