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.