Is it possible to import only certain variables from a SPSS file. I know that read.spss in the foreign library will bring the data into R but can I choose to important only chosen variables from the SPSS dataset to R? Thanks for your help. R -- View this message in context: http://r.789695.n4.nabble.com/Data-import-tp3842196p3842196.html Sent from the R help mailing list archive at Nabble.com.
Why would that be preferable to dropping the variables after importing the whole dataset? Daniel sassorauk wrote:> > Is it possible to import only certain variables from a SPSS file. > > I know that read.spss in the foreign library will bring the data into R > but can I choose to important only chosen variables from the SPSS dataset > to R? > > Thanks for your help. > > R >-- View this message in context: http://r.789695.n4.nabble.com/Data-import-tp3842196p3842485.html Sent from the R help mailing list archive at Nabble.com.
I have never used that function, but I know that with read.csv() you can do the following to select only the columns you want: chosen_vars <- read.csv("Workbook1.csv", header=T)[c("variable1", "variable3")] HTH sassorauk wrote:> > Is it possible to import only certain variables from a SPSS file. > > I know that read.spss in the foreign library will bring the data into R > but can I choose to important only chosen variables from the SPSS dataset > to R? > > Thanks for your help. > > R >-- View this message in context: http://r.789695.n4.nabble.com/Data-import-tp3842196p3842600.html Sent from the R help mailing list archive at Nabble.com.
You can with the routines in the memisc library. You can open a file using spss.system.file and then import a subset using subset. Look in the help pages of spss.system.file for examples. HTH Jan On 09/25/2011 11:56 PM, sassorauk wrote:> Is it possible to import only certain variables from a SPSS file. > > I know that read.spss in the foreign library will bring the data into R but > can I choose to important only chosen variables from the SPSS dataset to R? > > Thanks for your help. > > R > > -- > View this message in context: http://r.789695.n4.nabble.com/Data-import-tp3842196p3842196.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
Thanks for your responses. Ben is right that I am looking for a way to import a subset of data from SPSS into R. If I could do this it would mean not having to save large datasets which takes a long time and would mean duplicating a lot of the same information each time. I find SPSS slow to produce crosstabs and if I can make use of R then that would be great. R -- View this message in context: http://r.789695.n4.nabble.com/Data-import-tp3842196p3843820.html Sent from the R help mailing list archive at Nabble.com.