[R] cumulative data monthly

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Jan 27 19:03:44 CET 2019


Hello,

See if the following can get you started.
It uses package CRAN zoo, function as.yearmon.

dati$MES <- zoo::as.yearmon(dati$DATAORA)
PMES <- ave(dati$PREC, dati$MES, FUN = cumsum)

plot(dati$DATAORA, PMES)


Hope this helps,

Rui Barradas

Às 15:25 de 27/01/2019, Diego Avesani escreveu:
> Dear all,
> 
> I have a set of data with has hourly value:
> 
> # ID
> # Lo
> # L
> # Q
> Time,    T, RH,PSFC,DIR,VEL10, PREC, RAD, CC,FOG
> yyyy-mm-dd hh:mm,   °C,  %, hPa, °N,  m/s, mm/h,W/m²,  %,-
> 2012-01-01 06:00, -0.1,100, 815,313,  2.6,  0.0,   0,  0,0
> 2012-01-01 07:00, -1.2, 93, 814,314,  4.8,  0.0,   0,  0,0
> 2012-01-01 08:00,  1.7, 68, 815,308,  7.5,  0.0,  41, 11,0
> 2012-01-01 09:00,  2.4, 65, 815,308,  7.4,  0.0, 150, 33,0
> .....
> .....
> 
> I was able to read it,  create my-own data frame and to plot the total
> cumulative function.
> This is basically what I have done:
> 
> dati <- read.csv(file="116.txt", header=FALSE, sep="," ,
> na.strings="-999",skip = 6)
> colnames(dati)=c("DATAORA","T", "RH","PSFC","DIR","VEL10", "PREC", "RAD",
> "CC","FOG")
> 
> dati$DATAORA<-as.POSIXct(strptime(dati$DATAORA,format="%Y-%m-%d %H:%M"))
> 
> 
> P <- cumsum(dati$PREC)
> plot(dati$DATAORA, P)
> 
> I would like to select the data according to an starting and ending date.
> In addition, I would like to plot the monthly and not the total one.
> I mean, I would like to have a cumulative plot for each month of the
> selected year.
> 
> I am struggling with "ddply" but probably it is the wrong way.
> 
> Could someone help me?  Really Really thanks,
> 
> 
> Diego
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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