How to separate text answers in R?

Asked

Viewed 245 times

0

I’m sure my doubt should be super simple to be solved so far I have not had any positive results in any of the tutorials I downloaded.

I am working on a df in R that there is a column that the answers were separated by ; that is, each participant could answer one more option (Example:Knowledge mapping, Automatic feedback, Artificial intelligence, Collaboration and co-authoring). I need to separate the answers so I can identify how many users answered each of the options without changing the number of participants/respondents.

Thank you very much, Priscilla.

  • Welcome to Stackoverflow! Unfortunately, this question cannot be reproduced by anyone trying to answer it. Please, take a look at this link and see how to ask a reproducible question in R. So, people who wish to help you will be able to do this in the best possible way.

  • 3

    I’d do anything like resp <- lapply(df, strsplit, ","); table(unlist(resp)). But without seeing the data it is impossible to be sure. Edit the question with the departure of dput(head(df, 20)), please.

1 answer

3

Use the function multi.split package questionr. To view the result, use multi.table.

v <- c("red,blue","green","red,green","blue,red")
multi.split(v, split.char = ",")
## Tabela de frequências
multi.table(multi.split(v, split.char = ","))

        n %multi
v.blue  2     50
v.red   3     75
v.green 2     50

Browser other questions tagged

You are not signed in. Login or sign up in order to post.