Hi Lauren, As Sarah noted, if your blank responses are coming as NAs, it may be best to leave them alone until you have done the calculations:
survey$responses<-!is.na(survey[,c("q1","q2","q3")]) survey$sum_survey<-rowSums(survey[,c("q1","q2","q3")],na.rm=TRUE) # the next line returns a logical vector that you can use to subset # like this survey[q_complete,] q_complete<-complete.cases(survey[,c("q1","q2","q3")]) then set your NAs to zeros if you need to. Jim On Wed, Aug 17, 2016 at 4:51 AM, Lauren Bolger <lebol...@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@r-project.org 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. ______________________________________________ R-help@r-project.org 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.