[R] (no subject)
    arun 
    smartpink111 at yahoo.com
       
    Wed Feb 26 09:34:08 CET 2014
    
    
  
Hi Dila,
Try:
transform(melt(dat,id.var="Day"),Month=match(variable,month.abb),Year=2012,Amount=value)[,-c(2:3)]
A.K.
On Tuesday, February 25, 2014 11:41 PM, dila radi <dilaradi21 at gmail.com> wrote:
Dear Arun,
sorry for asking again.
Assume that we used the sama data set 
dat <- read.table(text="Day Jan Feb Mar Apr
  1 0 2.5 0.5 2
  2 0 6.5 0 29
  3 0 9.5 0 0
  4 0 0 8 0.5
  5 0 5 0.5 110.5
  6 0 4 3.5 22
  7 11 0 12.5 3.5
  8 0 5 8 36.5",sep="",header=TRUE)
But now, I want to split the date into Day, Month and Year as follow:
Day       Month           Year      Amount
  1             1               2012       0.0
   2            1               2012       0.0
  3             1               2012       0.0
....................
..................
How do I achieved that? Thank you so much.
Regards,
Dila  
On 24 February 2014 20:32, arun <smartpink111 at yahoo.com> wrote:
>
>Hi Dila,
>Glad to know it works.
>Regards,
>Arun
>
>
>On Monday, February 24, 2014 10:59 PM, dila radi <dilaradi21 at gmail.com> wrote:
>
>Thank you Arun. I already tried it and it works!! Thank you so much.
>
>
>
>On 24 February 2014 19:47, arun <smartpink111 at yahoo.com> wrote:
>
>Hi,
>>Try:
>>Assuming your dataset looks like below (please use ?dput)
>>
>>dat <- read.table(text="Day Jan Feb Mar Apr
>>  1 0 2.5 0.5 2
>>  2 0 6.5 0 29
>>  3 0 9.5 0 0
>>  4 0 0 8 0.5
>>  5 0 5 0.5 110.5
>>  6 0 4 3.5 22
>>  7 11 0 12.5 3.5
>>  8 0 5 8 36.5",sep="",header=TRUE)
>>library(reshape2)
>>
>>res <- transform(melt(dat,id.var="Day"),Date=paste(Day,match(variable,month.abb),2012,sep="/"),Amount=value)[,-c(1:3)]
>>A.K.
>>
>>
>>
>>
>>
>>On Monday, February 24, 2014 10:20 PM, dila radi <dilaradi21 at gmail.com> wrote:
>>Hi all,
>>
>>I have a data set in this form:
>>
>>Year: 2012
>>Day Jan Feb Mar Apr  1 0 2.5 0.5 2  2 0 6.5 0 29  3 0 9.5 0 0  4 0 0 8 0.5
>>5 0 5 0.5 110.5  6 0 4 3.5 22  7 11 0 12.5 3.5  8 0 5 8 36.5
>>I want to rearrange the data in this form:
>>
>>    Date            Amount
>>1/1/2012              0
>>2/1/2012              0
>>3/1/2012              0
>>4/1/2012              0
>>...                       ...
>>...                       ...
>>
>>How can I achieve this?
>>
>>Thank you in advanced!
>>
>>Regards,
>>Dila
>>
>>    [[alternative HTML version deleted]]
>>
>>______________________________________________
>>R-help at r-project.org mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
    
    
More information about the R-help
mailing list