Data import

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Data import

sassorauk
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
Reply | Threaded
Open this post in threaded view
|

Re: Data import

Daniel Malter
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
Reply | Threaded
Open this post in threaded view
|

Re: Data import

Brad Schneid
In reply to this post by sassorauk
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
Reply | Threaded
Open this post in threaded view
|

Re: Data import

Jan van der LAan-2
In reply to this post by sassorauk
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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Data import

bbolker
In reply to this post by Brad Schneid
B77S <bps0002 <at> auburn.edu> writes:

>
> 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")]
>


  This is not actually selectively importing: it's importing the
whole thing and *then* selecting the relevant columns.
  If the original poster is trying to avoid importing the whole
data set because (for example) it's got a gigantic number of
columns and will be very slow and/or tax their system, then this
idiom won't help.

  Ben Bolker

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Data import

sassorauk
In reply to this post by sassorauk
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
Reply | Threaded
Open this post in threaded view
|

Re: Data import

Brad Schneid
In reply to this post by bbolker
I see what you mean.
Sorry and thanks for pointing that out to me Ben.

bbolker wrote
B77S <bps0002 <at> auburn.edu> writes:

>
> 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")]
>


  This is not actually selectively importing: it's importing the
whole thing and *then* selecting the relevant columns.
  If the original poster is trying to avoid importing the whole
data set because (for example) it's got a gigantic number of
columns and will be very slow and/or tax their system, then this
idiom won't help.

  Ben Bolker

______________________________________________
[hidden email] 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.