Re: [R] Importing data to a multidimensional array

From: Uwe Ligges <ligges_at_statistik.tu-dortmund.de>
Date: Wed, 05 Nov 2008 18:40:35 +0100

Jon Wong wrote:
> Hi,
> I was wondering if I could get some help on importing data into a
> three-dimensional array?
>
> I am importing data from several text files:
>
> dsdir<-"c:/documents and settings/desktop/07082008/" # path to files
> dsfb1<-"07082008-DI4129b.dat" # file base name
>
> firsthour<-13 # first hour of observation which changes from 6am to 1pm from
> day to day
> lasthour<-20 # last hour of observation which also changes from 6 - 8pm
>
> for(i in firsthour:lasthour)
> assign(paste("ds",i,"a",sep=""),read.delim(file=paste(dsdir,i,dsfb1,sep=""),
> header=F, sep="\t", skip=5))

Always a bad idea to make such assignment, better assign into a list "ds" with elements called a13...a20, for example. You can easily make it 3D by unlist() it and assigning new dim() attributes afterwards, for example.

Or perhaps even better, read each data.frame, coerce to a matrix which you insert into the correct position of a pre-defined array().

Uwe Ligges

> This code generates matrices from ds13a:ds20a containing data from the
> respective text files, but I need this in a three-dimensional array for
> further processing. The observation counts in the imported files vary from
> one to another, and there is never a set number of files to be imported.
> Any help is greatly appreciated. Thanks
>
> Sincerely,
> Jon
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org 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_at_r-project.org 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 Wed 05 Nov 2008 - 17:45:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Nov 2008 - 18:30:22 GMT.

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

list of date sections of archive