# [R Survey Analysis] Problem counting number of responses

4 messages
Open this post in threaded view
|

## [R Survey Analysis] Problem counting number of responses

 M ​y dataset includes a survey completed by research participants to evaluate quality of life. A few things regarding the survey:    - *not all questions must be answered​ for the total score *    - questions left blank are coded as "0"    - ​the number of questions answered must be determined in order to    compute the total score *Sample Code​* > q1 <- ifelse(is.na(survey, 0, survey\$q1) > q2 <- ifelse(is.na(survey, 0, survey\$q2) > q3 <- ifelse(is.na(survey, 0, survey\$q3) > survey\$sum.survey <- q1 + q2 + q3 > survey\$responses <- # HELP ????? *> # HELP PART 1 ------------------------------* *> # need help determining number of questions the respondents answered* > *# HELP PART 2 -------------------------------* *> # I want to look at the subset of the population that completed all the questions* ​ ​ ​Thanks for your help!! It means a lot​ :)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: [R Survey Analysis] Problem counting number of responses

 Lauren, The easier that you make it for us to help you, the more likely you are to get help and the more helpful the answers will be. First, please post in plain text (not HTML).  Second, reproducible code (including sample data) helps us help you. Your code above is incorrect, the 3 lines with "ifelse" have more left parentheses than right parentheses. Is "survey" a data frame? or something else? Best guess from your code is that you want something like: survey\$responses <- with(survey, !is.na(q1) + !is.na(q2) + !is.na(q3)) the "with" function just makes it so you don't have to prepend everything with "survey\$", the "!" inverts logic so that it shows those that are not NA and when you sum logicals they are converted to 0/1. With 3 questions then you can subset your data like: survey[ survey\$nesponses==3, ] to see those that answered (or did not result in NA) 3 questions. On Tue, Aug 16, 2016 at 12:51 PM, Lauren Bolger <[hidden email]> wrote: > M > y dataset includes a survey completed by research participants to evaluate > quality of life. A few things regarding the survey: > > >    - > *not all questions must be answered for the total score * >    - questions left blank are coded as "0" >    - the number of questions answered must be determined in order to >    compute the total score > > > *Sample Code* > >> q1 <- ifelse(is.na(survey, 0, survey\$q1) > >> q2 <- ifelse(is.na(survey, 0, survey\$q2) > >> q3 <- ifelse(is.na(survey, 0, survey\$q3) > >> survey\$sum.survey <- q1 + q2 + q3 > >> survey\$responses <- # HELP ????? > *> # HELP PART 1 ------------------------------* > *> # need help determining number of questions the respondents answered* > >> *# HELP PART 2 -------------------------------* > *> # I want to look at the subset of the population that completed all the > questions* > > > > > Thanks for your help!! It means a lot :) > >         [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. [hidden email] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.