Tag Info

New answers tagged

5

I think those who find this kind problem challenging enough to ask for s solution on this site are likely to be open to a tutorial answer giving a step-by-step exposition. The overall plan is to develop a function that will take one item from the table, compute the date difference for that item, and insert it into the item. With such a function, any data ...


5

My proposal: {##, data[[1, 1]] ~DayCount~ #} & @@@ data {{{2012, 6, 1}, 16, 0}, {{2012, 6, 8}, 14.24, 7}, ..., {{2012, 10, 9}, 4.53, 130}}


1

data /. {date_: {_, _, _}, v_} :> {date, v, DateDifference[{2012, 6, 1}, date]} {{{2012, 6, 1}, 16, Quantity[0, "Days"]}, {{2012, 6, 8}, 14.24, Quantity[7, "Days"]},... If you are using V10 you need to use QuantityMagnitude to get the number of days as a number. This goes for all answers using DateDifference. data /. {date_: {_, _, _}, v_} :> ...


2

{## & @@ #, DateDifference[data[[1, 1]], First@#]} & /@ data (* {{{2012, 6, 1}, 16, 0}, {{2012, 6, 8}, 14.24, 7}, {{2012, 6, 15}, 13.7, 14}, {{2012, 6, 22}, 12.31, 21}, {{2012, 6, 29}, 11.5, 28}, {{2012, 7, 6}, 10.08, 35}, {{2012, 7, 13}, 9.18, 42}, {{2012, 7, 20}, 8.65, 49}, {{2012, 7, 27}, 7.8, 56}, {{2012, 8, 3}, 7.51, 63}, ...


4

DateDifference[First@First@data, #] & /@ (First /@ data) Append[#, #2] & @@@ Thread@{data, %} {0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84, 91, 98, 105, 112, 119, 126, 130} {{{2012, 6, 1}, 16, 0}, {{2012, 6, 8}, 14.24, 7}, {{2012, 6, 15}, 13.7, 14}, {{2012, 6, 22}, 12.31, 21}, {{2012, 6, 29}, 11.5, 28}, {{2012, 7, 6}, 10.08, 35}, {{2012, ...


4

I would use: DateRange[{2000}, {2010}, "Year"][[All, {1}]] {{2000}, {2001}, {2002}, {2003}, {2004}, {2005}, {2006}, {2007}, {2008}, {2009}, {2010}} % ~Select~ LeapYearQ {{2000}, {2004}, {2008}} Note the {1} in the Part parameters; see Head and everything except Head?


4

I'm afraid you now have to extract that information by yourself. This performs the same function as eldo's code, but instead of using Map twice I use Composition. It is also showcasing the new Mathematica 10 syntax. Map[List@*First]@*Select[LeapYearQ]@DateRange[{2000}, {2020}, "Year"] {{2000}, {2004}, {2008}, {2012}, {2016}, {2020}} In order to ...


2

As to your first question: List /@ First /@ Select[DateRange[{2000}, {2020}, "Year"], LeapYearQ] {{2000}, {2004}, {2008}, {2012}, {2016}, {2020}}


2

This is due to the fact that the first data point pulled (for {2014,8,14}) is used to calculate the first return value, which is on {2014,8,15}. To calculate the return for {2014,8,14} the previous day is needed. In order to get matching starting dates in a reliable way, it is best to determine the starting date, e.g. firstDate={2014, 01, 05} and than ...


2

Some possibilities to plot GridLines with DateListPlot: DateListPlot[{ {{2014, 1, 1}, 1}, {{2014, 1, 2}, 2}, {{2014, 1, 3}, 3}}, PlotTheme -> "Detailed"] DateListPlot[{ {{2014, 1, 1}, 1}, {{2014, 1, 2}, 2}, {{2014, 1, 3}, 3}, {{2014, 1, 4}, 1}}, GridLines -> {{{{2014, 1, 2}, Red}, {"Jan 3, 2014", Green}}, Automatic}] ...


1

Looks like AbsoluteTime might get you close. My examples here don't include the final 04:00. In[1]:= AbsoluteTime["2014-07-31T10:19:08.985"] Out[1]= 3.615790748985000*10^9 In[2]:= ToExpression /@ StringSplit["2014-07-31T10:19:08.985", ("-" | "T" | ":")] Out[2]= {2014, 7, 31, 10, 19, 8.985} In[3]:= AbsoluteTime@% Out[3]= 3.615790748985000*10^9


3

Here's my current workaround. Works only if the distinct time coordinates are sufficiently separated. corr[z_] := Module[{z1, z2}, z1 = SplitBy[SortBy[z, First], #[[1]] &]; z2 = Table[ Transpose[{z1[[k, All, 1]] + Range[0, Length[z1[[k]]] - 1], z1[[k, All, 2]]}], {k, Length[z1]}]; Partition[Flatten[z2], 2]] and ...


5

It's fun to use Associations as a circular linked list, which automatically handles the cyclic nature of these ranges: Clear@monthRange monthRange[start_, end_] := Module[{monthsLL, head}, monthsLL = Fold[ <|#2 -> #|> &, Reverse[DataPaclets`CalendarDataDump`MonthList["Gregorian"] ~Join~ {monthsLL}] ]; head = ...


5

1) Get the list of days and months. Note that days are represented in MMA as symbols (and not strings as months are), hence the use of ToString to make them in a consistent type with the list of months (credit to @Mr.Wizard for this tip). monthList=DateValue[{2014,#,1},"MonthName"]&/@Range[12] (* ...


11

For full ranges There is the function DayRange that can be used for this purpose, but not in the same simple way like CharacterRange. For the days: DayName /@ DayRange[Today, Today ~DatePlus~ {{1, "Week"}, {-1, "Day"}}] {Wednesday, Thursday, Friday, Saturday, Sunday, Monday, Tuesday} For the months: DateValue[#, "MonthName"] & /@ DayRange[Today, ...


0

Again with the understanding that an answer has already been accepted. I submit the following only as an exercise: Clear[repeatdaterange]; repeatdaterange[startdate_, enddate_] := Module[{startyear, startmonth, startday, endyear, endmonth,endday, curyear, curmonth, curday, stopyear, stepping, lastmonth, listofdates, rangeofdates}, {startyear, ...


2

My answer is based on @eldo's and @ubpdqn's answer (thanks guys!). Remove // Flatten[#, 1] & to get the dates grouped into years. Clear[seismaticaDates] seismaticaDates[year_,{mfrom_,dfrom_},{mto_,dto_},{cy_,cm_,cd_}]:= Module[{dateRangeFunc,allDates}, dateRangeFunc=DateRange[{#,mfrom,dfrom},{#,mto,dto}]&; (* Defining 2 allDates functions to prevent ...


2

Borrowing from @ubpdqn, my interpretation of the question (which, hopefully, should also be valid in 2015): td = Today // Normal; {cy, cm, cd} = Take[td, 3]; days = Flatten[DateRange[{#, 7, 4}, {#, 10, 4}, "Day"] & /@ Range[1970, cy], 1]; Which[ Today > Interpreter["Date"]["04/October/" <> ToString@cy], days, Today < ...


2

So the solution would be (thanks to Pickett) DateString[#, {"Year", "-", "Month", "-", "Day", " ", "Hour", ":", "Minute", ":", "Second"}]&/@dates Once the transformation done, export the thing !



Top 50 recent answers are included