################## # MDS ################## #Original script: http://mhermans.net/static/postdata/r-examples/neighbours-mds/neighbours-mds-example.html #Czech data - https://dbk.gesis.org/dbksearch/sdesc2.asp?no=4770&db=e&doi=10.4232/1.10165 library(foreign) # load the foreign package mydata = read.spss("http://siret.cz/hoksza/teaching/vis/ds/ZA4770_v1-1-0-spss.txt", to.data.frame=TRUE) neighbors=mydata[,paste("v", sapply(c(46:60), toString), sep="")] names(neighbors) <- c("criminal", "orace", "leftw", "drink", "rightw", "lfam", "emo", "muslim", "immig", "aids", "drugs", "homo", "jew", "gypsy", "christ") #-5 other missing #-4 question not asked #-3 not applicable #-2 no answer #-1 don't know #-0 not mentioned #-1 mentioned neighbors <- na.omit(neighbors) # remove missings listwise convertAnswer <- function(answer){ if (answer == "mentioned") return(1) else return(0) } neighbors.numeric <- as.data.frame(lapply(neighbors,FUN = function(x) {sapply(x,FUN=convertAnswer)}))