Here is the code that I was using to parse some strings and then create a dataset from them. I guess the problem is when Mapping some of the expressions the result is a list and then this is included in a larger list. Really want to get the result without the List property, so to remove in as I have to now. The other problem is that when using RegularExpression is that the matches are returned as String and I will have to convert that later to Integer for processing.
In[553]:= lineSplit // InputForm
Out[553]//InputForm=
{{"Game 1", " 3 blue, 4 red", " 1 red, 2 green, 6 blue", " 2 green"},
{"Game 2", " 1 blue, 2 green", " 3 green, 4 blue, 1 red", " 1 green, 1 blue"},
{"Game 3", " 8 green, 6 blue, 20 red", " 5 blue, 4 red, 13 green", " 5 green, 1 red"},
{"Game 4", " 1 green, 3 red, 6 blue", " 3 green, 6 red", " 3 green, 15 blue, 14 red"},
{"Game 5", " 6 red, 1 blue, 3 green", " 2 blue, 1 red, 2 green"}}
In[549]:= fxx[arg1_] := Module[{game, sets},
game = StringCases[RegularExpression["(\\d+)"] -> "$1"][First[arg1]][[1]];
sets = StringCases[RegularExpression["(\\d+) (\\w+)"] -> "$2" -> "$1"][
Rest[arg1]];
<|Flatten[{"game" -> game, "blue" -> 0, "red" -> 0, "green" -> 0, #}]|> & /@
sets
]
In[550]:= fxx /@ lineSplit (* this results in the List-of-Lists *)
Out[550]= {{<|"game" -> "1", "blue" -> "3", "red" -> "4",
"green" -> 0|>, <|"game" -> "1", "blue" -> "6", "red" -> "1",
"green" -> "2"|>, <|"game" -> "1", "blue" -> 0, "red" -> 0,
"green" -> "2"|>}, {<|"game" -> "2", "blue" -> "1", "red" -> 0,
"green" -> "2"|>, <|"game" -> "2", "blue" -> "4", "red" -> "1",
"green" -> "3"|>, <|"game" -> "2", "blue" -> "1", "red" -> 0,
"green" -> "1"|>}, {<|"game" -> "3", "blue" -> "6", "red" -> "20",
"green" -> "8"|>, <|"game" -> "3", "blue" -> "5", "red" -> "4",
"green" -> "13"|>, <|"game" -> "3", "blue" -> 0, "red" -> "1",
"green" -> "5"|>}, {<|"game" -> "4", "blue" -> "6", "red" -> "3",
"green" -> "1"|>, <|"game" -> "4", "blue" -> 0, "red" -> "6",
"green" -> "3"|>, <|"game" -> "4", "blue" -> "15", "red" -> "14",
"green" -> "3"|>}, {<|"game" -> "5", "blue" -> "1", "red" -> "6",
"green" -> "3"|>, <|"game" -> "5", "blue" -> "2", "red" -> "1",
"green" -> "2"|>}}
I will keep playing around with it and learn how to get the data structures that I need. That what I am trying to do now is learn how to perform some of the transformations that I am used to from using R