This seems like it should be a simple question, but I am running into some difficulty in doing this with Mathematica. Right now, I have a list like this:
data1={0, 0, 0, 0, 0, 0, 3, 1, 10, 3, 11, 1, 0, 0, 32, 0, 1, 0, 5, 0, 2, 0, 25, 0, 1, 0, 1,
0, 0, 0, 0, 7, 0, 0, 0, 0, 13, 4, 0, 5, 0, 0, 2, 3, 4, 0, 0, 95, 4, 16, 11, 2, 0, 0,
81, 35, 0, 0, 0, 33, 0, 0, 0, 0, 0, 5, 42, 0, 0, 0};
I want to insert "1997" into the list after each element and transpose it, so that it will look like so: {{1997,0},{1997,0},{1997,0}...}. So far so good.
Unfortunately, the only way I know how to do this is to manually create a list of equal length to data1 (70 "1997"s in a row). I also do not know how to create a list that is just 70 "1997"s in a row. I've plumbed the documentation and tried every command I can think of, but the closest I can get are either functions or a list that resembles {{1997,0,1997,0,1997,0...} etc.
ConstantArray[1997,70]orTable[1997,{70}]. – wxffles Apr 25 '12 at 22:49ConstantArrayisn't in the "list manipulations" docs section, as it's a great command to have in one's list toolkit! – canadian_scholar Apr 25 '12 at 22:52Thread. – rcollyer Apr 25 '12 at 23:44Tuples. This question is really good example for testing efficiency of various methods. – Artes Apr 26 '12 at 02:10ConstantArrayto verbose, for my tastes, though, I do use it. If I want something terse, I useArray[1997&, 70]. I doubt it is faster to execute, but it is a lot faster to type! However,Developer`PackedArrayQ[Array[...]] == False, while it isTrueforConstantArray, implying a speed hit forArray. – rcollyer Apr 26 '12 at 02:49