#R-code for data preparation for LEM library(foreign) ESS3Slo<-read.spss(file="ESS3e03_1_Slovenia_sysMiss.sav",use.value.labels = FALSE, to.data.frame = TRUE) #individual records: vars <-c("B1","B2","B3") #select variables onlyComplete = TRUE #do we want only complete data (no missings) #make sure variables have only values 1-n with no missing codes selection<-ESS3Slo[,vars] #select vatiables selection <-data.frame(lapply(selection,factor)) meaningOfCodes<-lapply(selection,levels) #So you know what the codes mean meaningOfCodes selectionNum <-data.frame(lapply(selection,as.numeric)) if(onlyComplete){ selectionUsed<-selectionNumComp<-na.omit(selectionNum) } else { selectionUsed<-selectionNum0[is.na(selectionNum)]<-0 } dim(selectionUsed) # the number of recoreds must be specified in the input file write.table(selectionUsed,file="LEMrecords.dat",row.names = FALSE, col.names = FALSE) #recored with counts selectionNumCounts<-data.frame(ftable(selectionUsed)) dim(selectionNumCounts) # the number of recoreds must be specified in the input file write.table(selectionNumCounts,file="LEMrecordsCounts.dat", quote = FALSE, row.names = FALSE, col.names = FALSE) #table - the last variable moving fastest write.table(ftable(selectionNumComp),file="LEMtable.dat",row.names = FALSE, col.names = FALSE)