1
$\begingroup$

I have

{{{1986, 1, 15, 0, 0, 0.}, 2.28}, {{1986, 2, 15, 0, 0, 0.}, 2.26}, 
 {{1986, 3, 15, 0, 0, 0.}, 2.16}, {{1986, 4, 15, 0, 0, 0.}, 2.1}, 
 {{1986, 5, 15, 0, 0, 0.}, 1.96}, {{1986, 6, 15, 0, 0, 0.}, 1.85}, 
 {{1986, 7, 15, 0, 0, 0.}, 1.8}, {{1986, 8, 15, 0, 0, 0.}, 1.77}, 
 {{1986, 9, 15, 0, 0, 0.},}, {{1986, 10, 15, 0, 0, 0.}, 1.73}}

for some data.I want to remove that hour ,min,sec part and also some missing data for some days.You can see there.I want those dates also to be filtered and not included. How the code be? I want in this format{{{1986, 1, 15}, 2.28},{{1986, 2, 15}, 2.26},...

$\endgroup$
3
$\begingroup$

You could use pattern matching and replacements (with data assigned to your list):

data /. {{{__}, Null} -> Sequence[], {{a__, _, _, _}, b_} :> {{a}, b}}

{{{1986, 1, 15}, 2.28}, {{1986, 2, 15}, 2.26}, {{1986, 3, 15}, 2.16}, {{1986, 4, 15}, 2.1}, {{1986, 5, 15}, 1.96}, {{1986, 6, 15}, 1.85}, {{1986, 7, 15}, 1.8}, {{1986, 8, 15}, 1.77}, {{1986, 10, 15}, 1.73}}

$\endgroup$
5
$\begingroup$

With the understanding that an answer has been checked, in version 9 there is DayRound

DayRound[{1986, 1, 15, 0, 0, 0.}, All]
(* {1986, 1, 15} *)
$\endgroup$
3
$\begingroup$

You can use the pattern matching as @Sjoerd C. de Vries suggested, eg.

Cases[data, {d_, v_} :> {d[[1 ;; 3]], v}]

or

Cases[data, {{y_, m_, d_, ___}, v_} :> {{y, m, d}, v}]

Alternately you can extract specific parts of data using Part function and then combine them with Transpose

Transpose@{data[[All, 1, 1 ;; 3]], data[[All, 2]]}
$\endgroup$
2
$\begingroup$

Using:

data = {{{1986, 1, 15, 0, 0, 0.}, 2.28}, {{1986, 2, 15, 0, 0, 0.}, 
2.26}, {{1986, 3, 15, 0, 0, 0.}, 2.16}, {{1986, 4, 15, 0, 0, 0.}, 
2.1}, {{1986, 5, 15, 0, 0, 0.}, 1.96}, {{1986, 6, 15, 0, 0, 0.}, 
1.85}, {{1986, 7, 15, 0, 0, 0.}, 1.8}, {{1986, 8, 15, 0, 0, 0.}, 
1.77}, {{1986, 9, 15, 0, 0, 0.},}, {{1986, 10, 15, 0, 0, 0.}, 
1.73}};

I suggest:

{#[[1, 1 ;; 3]], #[[2]]} & /@ data

Or the more elegant but less intuitive:

{#1[[;; 3]], #2} & @@@ data
$\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.