Skip to content
Prev 333261 / 398506 Next

melt dataframe

Hi,
Try:
dat1 <- read.csv("precipitationRglimclim.csv",header=TRUE,stringsAsFactors=FALSE,sep="\t")
library(reshape2)
dat2M <- melt(dat1,id.var=c("year","month","day"))
dat2M1 <- dat2M[with(dat2M,order(year,month,day,variable)),]
?dim(dat2M1)
#[1] 1972320?????? 5
?row.names(dat2M1) <- 1:nrow(dat2M1)
?colnames(dat2M1)[4:5] <- c("site","rain")


16436*120
#[1] 1972320

A.K.
On Saturday, November 16, 2013 11:28 PM, Zilefac Elvis <zilefacelvis at yahoo.com> wrote:
Hello AK,
I would like to melt the attached dataframe (precipitationRglimclim.csv) into a format as in sampleRglimclim.csv.
I tried doing it using the reshape2 package but did not succeed.

Explanation: The daily data is for 120 sites (G1...G120). For each year, there are 12 months and for each month, there are 1...28 or 30 or 31 days.
Melt the dataframe such that each day in a month has 120 values?corresponding?to the 120 sites.

If you need further explanation let me know.
Thanks so much.
Atem.