Hello all,
I'm having difficulty getting one particular variable into R from SPSS
v. 16.0 for mac. R version is 2.10.1. I saved the relevant variables
from SPSS into a .csv file and then read them into R. All the
variables worked fine, except for one (enviro_spending). In the SPSS
file it is correctly coded as a nominal variable and there is nothing
that I can tell that distinguishes it from the others.
I have tried to include a good representation of reproduceable code
below along with the results I am obtaining.
Yours, Simon
The variables are as follows:
educ =c("university", "university")
trade_off =c("*this cell is blank*", "disagree")
age=c(45,43)
gender_1=c("female", "female")
eviro_spending=c("Less/Same", "Less/Same")
carbon_tax_agg=c("agree", "disagree")
y=data.frame(educ, trade_off, age, gender_1, enviro_spending,
carbon_tax_agg)
#The following are the original commands I used to read the .csv file
into R.
y=read.csv(file.choose(), header=TRUE)
#When I do the following, all the variable names are correct
names(y)
#When I do the following, all the data in the dataframe are correct.
y
#But when I do the following, I get the following results
y$enviro_spending
#NULL
is.character(y$enviro_spending)
#FALSE
is.factor(y$enviro_spending)
#FALSE
#I tried to save the single problematic variable from my spss file to
a .csv file as and then read that into R.
z=read.csv(file.choose(), header=TRUE)
#Just as before, calling the dataframe gives the data exactly as it
should
z
#less/same
#more
#less/same
#more
#more
#But when I call the specific variable, I get #NULL
z$enviro_spending
#NULL
*********************************
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstra?e 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html