Accessing level values (answer codes) in R from Limesurvey export -


i'm analysing data limesurvey questionnaire in r. 1 of survey questions asks people country of origin , uses dropdown list of countries. i've created labelset 3-letter iso country code limesurvey answer code , country name label:

labelset iso codes countries

when exporting limesurvey data r, both codes , labels saved r syntax file. codes saved 'level' factor, , label of course used label (abbreviated clarity):

data[, 7] <- as.character(data[, 7]) attributes(data)$variable.labels[7] <- "which country from?" data[, 7] <- factor(data[, 7], levels=c("afg","ala","alb", ..., "zmb","zwe"),labels=c("afghanistan","Åland islands","albania", ..., "zambia","zimbabwe")) names(data)[7] <- "q3_nationality" 

however, cannot figure out how access 3-letter iso code in r? great iso code, can feed rworldmap joincountrydata2map() function , plot data on map. (i know can pass country name function, that's more error prone.)

if examine variable, this:

> data$q3_nationality   [1] guyana   249 levels: afghanistan Åland islands albania algeria ... zimbabwe 

similarly, levels() gives me:

levels(data$q3_nationality)   [1] "afghanistan"                                    [2] "Åland islands"                                  [3] "albania"                                        [4] "algeria"                                        [5] "american samoa"  

no sign of "afg", "ala", "alb" iso answer codes.

trying convert character, gives me full label again:

as.character(levels(data$q3_nationality))   [1] "afghanistan"                                    [2] "Åland islands"                                  [3] "albania"                                        [4] "algeria"                                        [5] "american samoa"  

it great if tell me how access these!

i propose dirty solution in way, edit r-syntax-file , set levels labels well. however, if want use full names countries later on printing or plotting, have transform then. can use code syntax file in code, maybe on copy printing.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -