0

I have a csv file with data on grouping of cereal brands in an experiment. I have one row for each subject (~2000 subjects) and each row has a variable number of brand that people liked (text strings separated by commas)

srno Brands 1 GMI 'TOTAL' WG ORIG,POS H-C GRAPE NUTS ORIG,POST GREAT GRAINS CRUNCHY PCN 2 GMI TINY TST STB,GMI HONEY NUT CHEERIOS REG,GMI TINY TST BB,GMI APPLE CN TOAST CRUNCH 3 QKR SQUARES CN

I want to read the data into a data frame so that I have the brands in each row as one element of a list My goal is to be able to do a text mining analysis to explore similarities (ie brands that occur together)

I see a similar question asked a few years ago but I was not able to adapt the solution Text file to list in R

user3088463
  • 91
  • 1
  • 6

1 Answers1

0

Managed to work this out! I read in the csv file with StringsAsFactors=FALSE option (this is important)

`x = read.csv ("datafile.csv", stringsAsFactors=FALSE)        
#strings of brand names read into variable str_brand        
#the following stmt then turns the chars in str_brand into a list         
#note..I had the individual brands separated by commas in the csv file

brands_list <- stringr::str_split(x$str_brand,pattern = ",")

`

user3088463
  • 91
  • 1
  • 6