Re: [R] assignment of inidividual variables from spss save files

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Mon 13 Jun 2005 - 17:39:54 EST

Mike Day <mike_liz.day@tiscali.co.uk> writes:

> New to R, can't afford SPSS!
>
> Why can't I assign spss variables? Here are the details.
>
> > ### I've read in my collaborator's sav file using read.spss, eg

> > children = read.spss(filename)

> > ### It has many variables
> > length(children)
> [1] 347
> > ### and I would like to assign individual variables.
> > ### I can of course type out all the ones I want, eg
> > ADULTS11<-children[18]
> > ### But I'm lazy, so tried:
> > (function (x,n){assign(names(x[n]),x[n])})(children,2)
> > ### where
> > names(children[2])

> [1] "ADNUTS06"
> > ### but
> > ADNUTS06
> Error: Object "ADNUTS06" not found
> > ### I've tried lots of variations, including creating and
> > ### evaluating statements such as "ADNUTS06<-children[2]",
> > ### but without apparently yielding the required variable.
>
> I expect the answer will be "You shouldn’t start from here!"
> Ideas welcome.

Right. Instead, read up on the attach() function and with(). Read through "An Introduction to R" (manual, comes with R) and pay particular attention to chapter 6(.3). Beware the tricky bits relating to the search path and masking of variables.

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
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
Received on Mon Jun 13 17:53:50 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:33 EST