1

I have a Google form with some options that allow multiple responses. When the answers that form are transformed into a spreadsheet in Google Sheets, these multiple answers are separated by commas within the cells:

enter image description here

I want to import this spreadsheet into RStudio and transform the data into a data frame so that the responses of each participant are not separated by commas but by elements within the same column (in this case, the document format [driver's license" column ]).

Is it possible?

Thank you!

Sinval
  • 1,315
  • 1
  • 16
  • 25
  • 1
    Can you provide a reproducible example? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Sinval Jan 31 '21 at 19:08
  • share a copy of your sheet with example of desired result – player0 Jan 31 '21 at 19:11
  • FYI you don't necessarily have to do this in R, you can use Text to Columns in google sheets: https://support.google.com/docs/answer/6325535?co=GENIE.Platform%3DDesktop&hl=en – Kreuni Jan 31 '21 at 21:09

1 Answers1

1

That is a job for unnest_wider() in the tidyr package.

df <- data.frame(document = c("paper, digital", "paper, digital, system", "none"))

df %>% mutate(Separ = strsplit(as.character(document), ",")) %>% 
  tidyr::unnest_wider(Separ)

with output

# A tibble: 3 x 4
  document               ...1  ...2       ...3     
  <chr>                  <chr> <chr>      <chr>    
1 paper, digital         paper " digital"  NA      
2 paper, digital, system paper " digital" " system"
3 none  

Is that what you had in mind?

Taufi
  • 1,557
  • 8
  • 14