Skip to content
Prev 372271 / 398498 Next

Primer for working with survey data in R

You really should have pointed out that you cross-posted this question [1] so we wouldn't repeat things. You were already pointed at the task view on this subject there. Be sure to look for vignettes in the relevant packages.

I cannot point you to domain-specific examples, though I came across some in the brief search I did that lead me to your redundant question, so you probably ought to clarify what you have looked at and why it wasn't helpful. 

You mention specifying possible values... I will point out that many people turn off the automatic conversion to factor when reading categorical data, instead converting those columns to factors explicitly using the factor function:

dta$cat1 <- factor( dta$cat1, levels=c( "democrat", "republican", "libertarian", "independent", "other" ) )

There is also a package that focuses on factors ("forcats") that may have functions in it useful to your work.

I would put actual questions in a separate data frame with the question numbers and use the merge function if/when needed... but this is not my usual working area... some dedicated packages might put that info into attributes. 

[1] https://stats.stackexchange.com/questions/313220/doing-survey-analysis-in-r