[R] manipulate all files in folder

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Jan 10 13:03:07 CET 2003


You want a list of data frames, and tmpdata[[fn]].

You cannot put multiple data frames in one data frame (sensibly).

On Fri, 10 Jan 2003, Christian Schulz wrote:

> many thanks, but how  it's
> possible set my data.frames to get
> this as
> tmpdata[1]  etc.
>
> regards,christian
>
>
> test <- function(dir) {
> +        tmpdata <- data.frame(##here's the problem?##)
> +         for(fn in list.files(dir, full.names = TRUE)) {
> +           tmpdata[fn] <- read.spss(fn, use.value.labels=F,
> to.data.frame=T)
> +                 }
> +               return(tmpdata)
> +           }
> >>test("c:/Project/allbus/Data")
> [1] c:/Project/allbus/Data/fuzzyHermes.sav
> [2] c:/Project/allbus/Data/hermesKunden.sav
> [3] c:/Project/allbus/Data/hermesTertius.sav
> [4] c:/Project/allbus/Data/hermesWettbewerb.sav
> <0 rows> (or 0-length row.names)
> Warning messages:
> 1: replacement data has 2297 rows to replace 0 rows in:
> "[<-.data.frame"(*tmp*, fn, value = read.spss(fn, use.value.labels = F,
> 2: provided 8 variables to replace 1 variables in: "[<-.data.frame"(*tmp*,
> fn, value = read.spss(fn, use.value.labels = F,
> 3: replacement data has 2297 rows to replace 0 rows in:
> "[<-.data.frame"(*tmp*, fn, value = read.spss(fn, use.value.labels = F,
> 4: provided 192 variables to replace 1 variables in: "[<-.data.frame"(*tmp*,
> fn, value = read.spss(fn, use.value.labels = F,
> 5: replacement data has 2297 rows to replace 0 rows in:
> "[<-.data.frame"(*tmp*, fn, value = read.spss(fn, use.value.labels = F,
> 6: provided 25 variables to replace 1 variables in: "[<-.data.frame"(*tmp*,
> fn, value = read.spss(fn, use.value.labels = F,
> 7: replacement data has 430 rows to replace 0 rows in:
> "[<-.data.frame"(*tmp*, fn, value = read.spss(fn, use.value.labels = F,
> 8: provided 191 variables to replace 1 variables in: "[<-.data.frame"(*tmp*,
> fn, value = read.spss(fn, use.value.labels = F,
> >>ls()
> [1] "last.warning" "test"
>
> > test <- function(dir) {
> >   for(fn in list.files(dir, full.names = TRUE)) {
> >     tmpdata <- read.spss(fn, use.value.labels=F, to.data.frame=T)
> >     ....
> >   }
> > }
>
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list