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

Sarah Goslee sarah.goslee at gmail.com
Tue Aug 16 22:26:58 CEST 2016


Hi Lauren,

I'm not entirely sure what your sample code is suppoesd to do, since
it isn't complete R code, and it would be much easier to answer your
question if you provided sample data and didn't post in HTML.

dput(head(survey))

would be enough sample data, most likely.

But if I'm understanding correctly,
nanswered <- rowSums(survey != 0)
will give you for each respondent the number of questions answered.

or if they're actually NA instead of 0
nanswered <- rowSums(!is.na(survey))

then you can look at the distribution of those values, and use that
vector with subset() to get the population that answered all of your
questions.

The advantage of this approach is that you don't have to list each
question individually, in case you have lots.

Sarah

On Tue, Aug 16, 2016 at 2: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]]
>
-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list