Have been playing around with the R addon the past day or so.
The R WIki indicates one can write new SPSS data from R
http://wiki.r-project.org/rwiki/doku.php?id=tips:callingr:spss
Was wondering if anyone has a simple example of this?
So, I am crearing a new var in R called Var12.
begin program R.
data<-spssdata.GetDataFromSPSS()
data$Var12 <- (data$Var001 + data$Var002)
End program.
How would I get this new variable back into the existing SPSS
dataset?
Just trying to get familiar with how this addon works.
TIA,
Lance
The process of writing back a dataset has two parts: first you create
a dictioary and transmit it to SPSS. Then you send a data frame.
Here is an example from the course I will teach next week post the
annual SPSS Directions conference in Las Vegas. It creates an SPSS
dataset containing the residuals from an R function. Error handling
is managed through the tryCatch function.
HTH,
Jon Peck
dict<- spssdictionary.CreateSPSSDictionary( c("caseNumber", "Case
Number", 0, "F8.0", "nominal"),
c("lmResiduals", model, 0, "F8.2", "scale"))
tryCatch({
spssdictionary.SetDictionaryToSPSS(residualsdataset, dict)
df = data.frame(res$residuals)
spssdata.SetDataToSPSS(residualsdataset,
data.frame(row.names(df), res$residuals))
},
error=function(e) {print(e)
cat("Failed to create residuals dataset. Dataset name must not
already exist: ",
residualsdataset)
}
)