I have a dataset jdataSDG1
and like to reformat it as jdataSDG2
.
rawdataSDG1 ={
{"country", "indicator", 2001., 2002.},
{"Bhutan","consumption",76.9, 78.7},
{"Bhutan", "GDP",36.9,"Missing[]"},
{"Lao PDR","consumption",79.9, 85.7},
{"Lao PDR", "GDP", "Missing[]",55.},
{"Malaysia", "consumption", 174.6, 101.8},
{"Malaysia", "GDP",72.6, 74.6}
};
jdataSDG1 =
Join @@ Map[
a \[Function]
Dataset[AssociationThread[First@a, #] & /@
Rest[a]]][{rawdataSDG1}];
jdataSDG2 = {
{"time", "country ", "indicator", "data"},
{2001., "Bhutan", "consumption", 76.9},
{2001., "Bhutan", "GDP", 36.9},
{2001., "Lao PDR", "consumption", 79.9},
{2001., "Lao PDR", "GDP", "Missing[]"},
{2001., "Malaysia", "consumption", 174.6},
{2001., "Malaysia", "GDP", 72.6},
{2002., "Bhutan", "consumption", 78.7},
{2002., "Bhutan", "GDP", "Missing[]"},
{2002., "Lao PDR", "consumption", 85.7},
{2002., "Lao PDR", "GDP", 55.},
{2002., "Malaysia", "consumption", 101.8},
{2002., "Malaysia", "GDP", 74.6}
};
Note that I manually created jdataSDG2
.