Each week I import a dataset, and every week the dataset differs in length (the number of records). After the import I need to do some transformations. One of these transformations is the ReplaceAll.
problem: when the number of records is the same length of the number of parameters in de transformations, the ReplaceAll won't give the desired output.
For example:
data1 = {{"A1", "B1", "C1", "D1", "E1"}, {"A2", "B2", "C2", "D2",
"E2"}, {"A3", "B3", "C3", "D3", "E3"}, {"A4", "B4", "C4", "D4",
"E4"}, {"A5", "B5", "C5", "D5", "E5"}};
data1 /. {a_ , b_, c_ , d_ , e_} -> {"T", a , b, c, d, e}
The output is:
{"T", {"A1", "B1", "C1", "D1", "E1"}, {"A2", "B2", "C2", "D2", "E2"}, {"A3", "B3", "C3", "D3", "E3"}, {"A4", "B4", "C4", "D4", "E4"}, {"A5", "B5", "C5", "D5", "E5"}}
When the number of records differ from the number of parameters in the ReplaceAll function, like this:
data2 = {{"A1", "B1", "C1", "D1", "E1"}, {"A2", "B2", "C2", "D2",
"E2"}, {"A3", "B3", "C3", "D3", "E3"}, {"A4", "B4", "C4", "D4",
"E4"}};
data2 /. {a_ , b_, c_ , d_ , e_} -> {"T", a , b, c, d, e}
Now I get the output I want.
{{"T", "A1", "B1", "C1", "D1", "E1"}, {"T", "A2", "B2", "C2", "D2", "E2"}, {"T", "A3", "B3", "C3", "D3", "E3"}, {"T", "A4", "B4", "C4", "D4", "E4"}}
The same is truth for a list with six records:
data3 = {{"A1", "B1", "C1", "D1", "E1"}, {"A2", "B2", "C2", "D2",
"E2"}, {"A3", "B3", "C3", "D3", "E3"}, {"A4", "B4", "C4", "D4",
"E4"}, {"A5", "B5", "C5", "D5", "E5"}, {"A6", "B6", "C6", "D6",
"E6"}}
data3 /. {a_ , b_, c_ , d_ , e_} -> {"T", a , b, c, d, e}
{{"T", "A1", "B1", "C1", "D1", "E1"}, {"T", "A2", "B2", "C2", "D2", "E2"}, {"T", "A3", "B3", "C3", "D3", "E3"}, {"T", "A4", "B4", "C4", "D4", "E4"}, {"T", "A5", "B5", "C5", "D5", "E5"}, {"T", "A6", "B6", "C6", "D6", "E6"}}
Who has a suggestion for this problem?