OK, let's say we have a following list of lists of lists:
{{{4, 2}, {6, 2}, {2, 2}}, {{6, 3}, {4, 1}, {3, 1}, {2, 1}},
{{6,2}, {3, 2}, {4, 1}, {1, 1}}, {{4, 2}, {1, 2}, {6, 1}, {3, 1}},
{{4,3}, {6, 1}, {1, 1}, {2, 1}}, {{5, 3}, {1, 1}, {2, 1}, {3,1}},
{{2, 2}, {5, 2}, {6, 1}, {3, 1}}, {{1, 2}, {5, 2}, {3, 2}},
{{6, 2}, {3, 2}, {2, 1}, {5, 1}}, {{3, 3}, {6, 1}, {1, 1}, {5,1}},
{{5, 2}, {2, 2}, {4, 1}, {1, 1}}, {{2, 3}, {4, 1}, {6, 1}, {5, 1}},
{{1, 3}, {4, 1}, {3, 1}, {5, 1}}, {{4, 2}, {1, 2}, {2, 1}, {5, 1}}}
Now from such list, call it L
for convenience, I'd like to create a data frame where there are Length[L]
rows (so 14 rows in this case; that number is known in advance btw). Now, columns. I would like to have Length[Range[min,max,1]]
columns labeled by Range[min,max,1]
where
min = Min[Map[Min,Map[Min,L,{2}],{1}]]
and
max = Max[Map[Max,Map[Max,L,{2}],{1}]]
so for the case above we'd have min=1
and max=6
and so we'd have 6 columns, labelled by 1
,2
,3
,4
,5
and 6
. I hope that's clear. Now the entries of the data frame. So if we look at the first list of L
: {{4,2},{6,2},{2,2}}
.That corresponds to the first row of the data frame. Now {{4,2},{6,2},{2,2}}
tells us that we would 2 in the 4th column, 2 in the 6th column, 2 in the 2nd column. Also, we would like to have 0's elsewhere, so we'd have 0's in the 1st,3rd and 5th column of the first row. The main objective is to then transfer it to R and do the analysis there. I'd really appreciate some help.