R Markdown

This code uses the XML library to open an xml format table from the internet with an URL containing a date. As we are interested in collecting the all year (12 months), we iterate through the name of the URL to download the data every month.

We then plot one year of hourly data.

The river used is the Tomikawa, and the data comes from the Japanese Ministry MLIT:

富川(とみかわ)301071281105030 河川名:沙流川 http://163.49.30.82/cgi-bin/DspWaterData.exe?KIND=6&ID=301071281105030&BGNDATE=20100101&ENDDATE=20101231&KAWABOU=NO

tokawaURL2011 <-1


for (a in 1:9){
  tokawaURL2011[a]<-paste("http://163.49.30.82/cgi-bin/DspWaterData.exe?KIND=6&ID=301071281105030&BGNDATE=20110",a,"01&ENDDATE=20181231&KAWABOU=NO", sep="")
  
}

for (a in 10:12){
  tokawaURL2011[a]<-paste("http://163.49.30.82/cgi-bin/DspWaterData.exe?KIND=6&ID=301071281105030&BGNDATE=2011",a,"01&ENDDATE=20181231&KAWABOU=NO", sep="")

}

library(XML)
## Warning: package 'XML' was built under R version 4.0.3
tbl4 <- 1
for (a in 1:12) {
  
  tbl_xml <- readHTMLTable(tokawaURL2011[a])
  tbl2 <- as.data.frame(tbl_xml)
  tbl2 <- tbl2[6:29]
  tbl3<-t(tbl2)
  tbl3<-tbl3[-(1:48)]
  assign(paste("result",a,sep=""),c(tbl3))
  
}

tomikawa2011<-c(result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12)

plot(tomikawa2011, pch=16, xlab="hours", ylab="mm")
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introduced by coercion
lines(tomikawa2011)
## Warning in xy.coords(x, y): NAs introduced by coercion