Very succinct, Rui!
One warning to Diego.... automatic data recorders tend to use the local
standard timezone year-round. R by default assumes that timestamps
converted from character to POSIXct using the current timezone on your
computer... which may not be in the same zone that the logger was in but
even more commonly the computer follows daylight savings time. This leads
to NAs showing up in your converted timestamps in spring and duplicated
values in autumn as the data are misinterpreted. The easiest solution can
be to use
Sys.setenv( TZ="GMT" )
though if you need the actual timezone you can use a zone name of the form
"Etc/GMT+5" (5 hrs west of GMT).
Note that Rui's solution will only work correctly near the month
transition if you pretend the data timezone is GMT or UTC. (Technically
these are different so your mileage may vary but most implementations treat
them as identical and I have not encountered any cases where they differ.)
On January 27, 2019 10:03:44 AM PST, Rui Barradas <ruipbarradas at sapo.pt>
wrote:
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
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",
"CC","FOG")
dati$DATAORA<-as.POSIXct(strptime(dati$DATAORA,format="%Y-%m-%d
P <- cumsum(dati$PREC)
plot(dati$DATAORA, P)
I would like to select the data according to an starting and ending
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]]