0

I have this type of data (name: pmt4651) and want to separate and keep only the answers as independent elements (maybe in individual columns so that I can create a function to count and analyze them):

2
{"Q0":"An abstract musical score.\nAn abandoned set of flagpoles.\nA highway with a road sign to its right.\nA shelf protruding from a wall.\n"}

3
{"Q0":"An abstract flower.\nA setup diagram for an orchestral percussionist.\nA seating chart diagram for a wedding reception.\nA magic wand.\nA lollipop."}

I tried the separate and the strsplit function and to separate them by the "\n" sign but so far I failed. For the strsplit function I received an error with the note non-character argument. With this: sub(pattern = "{"Q0":"", replacement = "", x = pmt4651)

I tried to remove the symbols at the beginning of each row- because this is information I don't need. However, this failed as well.

Does anyone have an idea how I can solve this?

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
SVogels
  • 3
  • 2
  • What's the format of your data? – Adam Quek Aug 15 '17 at 09:42
  • It's a csv file and I stored the data as a data frame. Before storing it as a data frame R responded with "factor" when I asked for the class – SVogels Aug 15 '17 at 09:46
  • Try using `as.character()` – LAP Aug 15 '17 at 10:14
  • that worked! At least i don't get an error now anymore. However it doesn't separate the answers - I think I can't manipulate/arrange them because they are captured in the curly brackets and quotation marks. With former data I was able to remove them with the sub(pattern...) function (as mentioned above) but this time it doesn't work – SVogels Aug 15 '17 at 10:27
  • when you read the data try `read.csv("stuff.csv", stringsAsFactors=FALSE) ` it will prevent the factoization. – sconfluentus Aug 15 '17 at 12:04
  • hm, unfortunately R still gives me the same output with that code – SVogels Aug 15 '17 at 12:22
  • If you can, do `dput(head(yourImportedData))` and add that to the above so we can help better. – jav Aug 15 '17 at 14:01

0 Answers0