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

Greg Snow 538280 at gmail.com
Tue Aug 16 22:23:08 CEST 2016

```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

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 <lebolger at gmail.com> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help