One frequency for multiple choice questions

Hey,

We are very new to this so please be kind to us :slight_smile:

We did an online survey for our seminar and for one of the questions we had a multiple choice answer possibility. I would like to find out how many people clicked at least one of the possibilities.

Is there a code that can help me with that problem?

Thank you so much in advance!

If you have or can construct a data frame in the following form, where id represents students and A, B and C represent whether those questions were answered,

set.seed(42)
d <- data.frame(id = 1:20,
                A = sample(c(TRUE,FALSE),20, replace = TRUE),
                B = sample(c(TRUE,FALSE),20, replace = TRUE),
                C = sample(c(TRUE,FALSE),20, replace = TRUE))

then, add a column score to indicate if at least one of A, B or C was answered (TRUE)

set.seed(42)
d <- data.frame(id = 1:20,
                A = sample(c(TRUE,FALSE),20, replace = TRUE),
                B = sample(c(TRUE,FALSE),20, replace = TRUE),
                C = sample(c(TRUE,FALSE),20, replace = TRUE))

d$score <- ifelse(rowSums(d[2:4]) > 0,TRUE,FALSE)
d
#>    id     A     B     C score
#> 1   1  TRUE  TRUE  TRUE  TRUE
#> 2   2  TRUE  TRUE  TRUE  TRUE
#> 3   3  TRUE  TRUE FALSE  TRUE
#> 4   4  TRUE  TRUE FALSE  TRUE
#> 5   5 FALSE  TRUE FALSE  TRUE
#> 6   6 FALSE FALSE FALSE FALSE
#> 7   7 FALSE  TRUE FALSE  TRUE
#> 8   8 FALSE  TRUE FALSE  TRUE
#> 9   9  TRUE  TRUE FALSE  TRUE
#> 10 10 FALSE  TRUE  TRUE  TRUE
#> 11 11  TRUE FALSE FALSE  TRUE
#> 12 12 FALSE FALSE  TRUE  TRUE
#> 13 13  TRUE FALSE FALSE  TRUE
#> 14 14 FALSE FALSE FALSE FALSE
#> 15 15  TRUE  TRUE FALSE  TRUE
#> 16 16  TRUE FALSE FALSE  TRUE
#> 17 17 FALSE  TRUE  TRUE  TRUE
#> 18 18 FALSE FALSE FALSE FALSE
#> 19 19 FALSE FALSE  TRUE  TRUE
#> 20 20 FALSE FALSE  TRUE  TRUE

Created on 2023-03-01 with reprex v2.0.2

Wow, thank you so, so much for your fast reply!

1 Like

Oh, and the total would simply be sum(d$score)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.