1
$\begingroup$

I would like to create a time list for one day with range from 0:00 to 23:50 and transpose this list with a constant number 239 and then transpose these two lists. I tried to make it but it doesn't work:

timeList=Range[TimeObject[00,00,00],TimeObject[23,50,00],TimeObject[00,10,00]]
constantList=ConstantArray[239,Length[timeList]]
res=Transpose[{timeList,constantList}]

Can you help me? Thanks!

$\endgroup$
1
$\begingroup$

There are two issues with the code in the question: The first, as the error message tells us, is a problem with the syntax for TimeObject: It should be TimeObject[{h,m,s}], not TimeObject[h,m,s] (note the additional list around the arguments). The second issue is that TimeObject[…] is not a valid increment, for the same reason as you can't add two TimeObjects:

TimeObject[{00, 00, 00}] + TimeObject[{00, 10, 00}]
(* TimeObject[{0, 0, 0.}] + TimeObject[{0, 10, 0.}] *)

(It simply does not really make sense to say "add the time 13:00 to the time 11:00")

What we can do is add a quantity, e.g. Quantity[10, "min"]:

timeList = Range[TimeObject[{00, 00, 00}], TimeObject[{23, 50, 00}], Quantity[10, "min"]];
constantList = ConstantArray[239, Length[timeList]];
res = Transpose[{timeList, constantList}]
(* long output… *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.