Re: [R] SPSS to R Data file conversion

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 12 Apr 2008 20:35:25 -0400

?assign

I think this will work for you.

list=dir(pattern=".sav")
library(foreign)
for (i in 1:length(list)){

    # The saved data frame will be dat
    name=substring(list[i],1,nchar(list[i])-4)     assign(name, read.spss(list[i],to.data.frame=TRUE))     rname=paste("../R/",name,".rda",sep="")     # This uses dat for the saved dataframe rather than name     save(list=name,file=rname)
}

On Sat, Apr 12, 2008 at 8:17 PM, Robert Baer <rbaer_at_atsu.edu> wrote:
> I wrote a little routine to convert multiple spss data files (as data frames) to R data files. The code is as follows:
> #
> list=dir(pattern=".sav")
> library(foreign)
> for (i in 1:length(list)){
> # The saved data frame will be dat
> dat=read.spss(list[i],to.data.frame=TRUE)
> name=substring(list[i],1,nchar(list[i])-4)
> rname=paste("../R/",name,".rda",sep="")
> # This uses dat for the saved dataframe rather than name
> save(dat,file=rname)
> }
>
> This works just fine, but the data frames are all named dat when loaded into Rcmdr. It is not a problem to do an assignment at load time
> from the command line as in catnip=load("catnip.rda"), but Rcmdr uses the data frame name saved in the compressed .rda file upon loading.
>
> My variable "name" contains the string for the dataframe name I would like to use. I just can't figure out how to assign this name to the dat dataframe in the context of my loop.
>
> Any hints?
>
> Thanks,
> Rob Baer
>
>
> [[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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
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 Sun 13 Apr 2008 - 00:38:02 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 Sun 13 Apr 2008 - 04:30:27 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