Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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},...

share|improve this question
1  
You've seen Take[]? –  J. M. Jun 17 '13 at 11:09

4 Answers 4

up vote 3 down vote accepted

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}}

share|improve this answer

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} *)
share|improve this answer

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]]}
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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