Dear Michael,

Thanks for your codes. However, lapply does not work in my case since I've
some files missing in the data (say, the file data101.dat). Do you have any
suggestions on this?? Thank you very much.

Best Wishes,
Ray

On Wed, Jan 23, 2013 at 8:15 PM, R. Michael Weylandt <
michael.weylandt@gmail.com> wrote:

> On Wed, Jan 23, 2013 at 9:16 AM, Ray Cheung <ray1728@gmail.com> wrote:
> > Dear All,
> >
> > Sorry for asking a newbie question. I want to ask how to import 1000
> > datasets whose file names are labelled from data1.dat to data1000.dat
> into
> > R so that they are named M[1, , ] to M[1000, , ] accordingly. Thank you
> > very much.
> >,
>
> Hi Ray,
>
> I'm pretty sure you don't mean "named" M[1,,] etc. but rather that
> there's only one object M and that's how the slices come into
> existence:
>
> What you'll want to do is something like this:
>
> little_helpful_function(n){
>     file_name <- paste("data", n, ".dat", sep = "")
>     read.dta(file_name, ##OTHER PARAMETERS)
> }
>
> list_of_datasets <- lapply(1:1000, little_helpful_function)
>
> output <- do.call(c, list_of_datasets)
>
> dim(output) <- c(dim(list_of_datasets[[1]]), 1000)
>
> Or something like that. Note that I'm not quite sure what a dta file
> is, so I'll leave it to you to find an appropriate read.dta function.
>
> Feel free to write back (cc'ing the list) if you don't understand all
> of the above.
>
> Cheers,
> Michael
>
> > Best Regards,
> > Ray
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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.
>

	[[alternative HTML version deleted]]

