Skip to content

Data Rearrangement

1 message · arun

#
HI Dila,
You have to order it afterwards.
res <- transform(melt(dat,id.var=c("Year","Day")),Month=match(variable,month.abb),Amount=value)[,-c(3:4)]


res1 <- res[with(res,order(Year,Month,Day)),]
A.K.
On Friday, February 28, 2014 2:16 AM, dila radi <dilaradi21 at gmail.com> wrote:
Dear Arun,

Thank you so much for your concern.

It is slightly differ from what I want after I applied it on my data. My bad... It works by rearranging the data month by month.?

? ? Year Day Month Amount
1 ?2012 ? 1 ? ? 1 ? ?0.0
2 ?2012 ? 2 ? ? 1 ? ?0.0
3 ?2012 ? 3 ? ? 1 ? ?0.0
4 ?2012 ? 4 ? ? 1 ? ?0.0
5 ?2012 ? 5 ? ? 1 ? ?0.0
6 ?2012 ? 6 ? ? 1 ? ?0.0
7 ?2012 ? 7 ? ? 1 ? 11.0
8 ?2012 ? 8 ? ? 1 ? ?0.0
9 ?2013 ? 1 ? ? 1 ? ?0.0
10 2013 ? 2 ? ? 1 ? ?0.0
11 2013 ? 3 ? ? 1 ? ?0.0
12 2013 ? 4 ? ? 1 ? ?0.0
13 2013 ? 5 ? ? 1 ? ?0.0
14 2013 ? 6 ? ? 1 ? ?0.0
15 2013 ? 7 ? ? 1 ? 11.0
16 2013 ? 8 ? ? 1 ? ?0.0
17 2012 ? 1 ? ? 2 ? ?2.5
18 2012 ? 2 ? ? 2 ? ?6.5
19 2012 ? 3 ? ? 2 ? ?9.5
20 2012 ? 4 ? ? 2 ? ?0.0
21 2012 ? 5 ? ? 2 ? ?5.0
22 2012 ? 6 ? ? 2 ? ?4.0
23 2012 ? 7 ? ? 2 ? ?0.0
24 2012 ? 8 ? ? 2 ? ?5.0
25 2013 ? 1 ? ? 2 ? ?2.5
26 2013 ? 2 ? ? 2 ? ?6.5
27 2013 ? 3 ? ? 2 ? ?9.5
28 2013 ? 4 ? ? 2 ? ?0.0
29 2013 ? 5 ? ? 2 ? ?5.0
30 2013 ? 6 ? ? 2 ? ?4.0
31 2013 ? 7 ? ? 2 ? ?0.0
32 2013 ? 8 ? ? 2 ? ?5.0
33 2012 ? 1 ? ? 3 ? ?0.5
34 2012 ? 2 ? ? 3 ? ?0.0
35 2012 ? 3 ? ? 3 ? ?0.0
36 2012 ? 4 ? ? 3 ? ?8.0
37 2012 ? 5 ? ? 3 ? ?0.5
38 2012 ? 6 ? ? 3 ? ?3.5
39 2012 ? 7 ? ? 3 ? 12.5
40 2012 ? 8 ? ? 3 ? ?8.0
41 2013 ? 1 ? ? 3 ? ?0.5
42 2013 ? 2 ? ? 3 ? ?0.0
43 2013 ? 3 ? ? 3 ? ?0.0
44 2013 ? 4 ? ? 3 ? ?8.0
45 2013 ? 5 ? ? 3 ? ?0.5
46 2013 ? 6 ? ? 3 ? ?3.5
47 2013 ? 7 ? ? 3 ? 12.5
48 2013 ? 8 ? ? 3 ? ?8.0
49 2012 ? 1 ? ? 4 ? ?2.0
50 2012 ? 2 ? ? 4 ? 29.0
51 2012 ? 3 ? ? 4 ? ?0.0
52 2012 ? 4 ? ? 4 ? ?0.5
53 2012 ? 5 ? ? 4 ?110.5
54 2012 ? 6 ? ? 4 ? 22.0
55 2012 ? 7 ? ? 4 ? ?3.5
56 2012 ? 8 ? ? 4 ? 36.5
57 2013 ? 1 ? ? 4 ? ?2.0
58 2013 ? 2 ? ? 4 ? 29.0
59 2013 ? 3 ? ? 4 ? ?0.0
60 2013 ? 4 ? ? 4 ? ?0.5
61 2013 ? 5 ? ? 4 ?110.5
62 2013 ? 6 ? ? 4 ? 22.0
63 2013 ? 7 ? ? 4 ? ?3.5
64 2013 ? 8 ? ? 4 ? 36.5

But, I want it to be year by year. ?I meant 2012 (Jan-April) followed by 2013 (Jan - April)

Your help is really helpful, but I have to do some alteration which is I stuck in rearranging it year by year.

Regards,?
Dila
On 27 February 2014 22:10, arun <smartpink111 at yahoo.com> wrote:
HI DIla,