Commit e64fe60d authored by jml's avatar jml
Browse files

update vignettes

parent ca918bc3
---
title: "basicr on data.luftkval.oslo10"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{luft}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
library(basicr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```
## Basic analysis on 'data.luftkval.oslo10' df.
### install
```R
library("devtools")
devtools::install_git("https://git.nilu.no/rdiagnosis/basicr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/friendlyr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/d.luft.oslyr.git")
```
### Get the 'data.luftkval.oslo10' dataset with friendlyr.
The dataset represents real observations, meaning that it contains errors.
It is possible to know the quality of the value by requesting the qa flags with 'friendlyr::qa()', cf this [vignette](https://git.nilu.no/rfriendlyr/friendlyr/blob/master/vignettes/data.luftkval.oslo10.Rmd)
```R
fromDate <- "2004/01/01 00:00:00"
toDate <- "2018/12/31 23:00:00"
timeResolution <- "hourly"
precision <- "hourly"
element_id <- c("NO2")
# station ids
station_id <- c("7","848","464","827","665","9","11","163","504","809")
# luft
luft <- friendlyr::ts(service="d.luft.oslyr",
fromDate=fromDate,toDate=toDate,precision=timeResolution,timeResolution=timeResolution,
element_id=element_id,station_id=station_id)
# filter -9900 values, used as NA
varnames <- setdiff(names(luft), friendlyts::get_name_date_col(precision))
tmp <- luft %>% select(names(luft)) %>%
tidyr::gather(variable, value, -c(friendlyts::get_name_date_col(precision))) %>%
dplyr::mutate(value = replace(value, value == -9900, NA)) %>%
tidyr::spread(variable, value) %>% friendlyts::as_tbl_friendlyts(precision=precision,date_type="friendlyts")
```
### Basic analysis.
```R
names(tmp)
res <- basicr::basicr(df=tmp,target="NO2_7")
res
res <- basicr::basicr(df=tmp,target="NO2_7",group="YEAR")
res
plot_tbl_basic(df=tmp,target="NO2_7",group="YEAR")
res <- basicr::basicr(df=tmp,target="NO2_7",group="MONTH")
res
plot_tbl_basic(df=tmp,target="NO2_7",group="MONTH")
res <- basicr::basicr(df=tmp,target="NO2_7",group="WDAY")
res
plot_tbl_basic(df=tmp,target="NO2_7",group="WDAY")
res <- basicr::basicr(df=tmp,target="NO2_7",group="HOUR")
res
plot_tbl_basic(df=tmp,target="NO2_7",group="HOUR")
```
---
title: "basicr on weather from nycflights13"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{luft}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
library(basicr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```
## Basic analysis on 'weather' from 'nycflights13' package.
### get dataset
```R
#install.packages("nycflights13")
library(nycflights13)
data(weather)
```
### 'weather' as friendlyts
```R
# There are some duplicated rows, I assume there were a maximum of 2 stations.
varnames <- setdiff(names(weather), c("year", "month", "day", "hour","time_hour"))
dup <- weather %>% select('origin':'hour') %>% duplicated %>% as.numeric
# keep time_hour as the only column related to date and time
tmp <- weather %>% mutate(dup=dup) %>% select('time_hour','dup',varnames)
tmp <- tmp %>%
tidyr::gather('variable', 'value', -c('dup','origin','time_hour')) %>%
tidyr::unite('var_tmp', 'origin','dup','variable') %>%
tidyr::spread('var_tmp', 'value')
# 'weather' as friendlyts
tmp <- friendlyts::friendlyts(df=tmp,date_col="time_hour",date_type="posixlt",tzone="EST")
```
### Basic analysis.
```R
names(tmp)
# Relative humidity
res <- basicr::basicr(df=tmp,target="EWR_0_humid")
res
res <- basicr::basicr(df=tmp,target="EWR_0_humid",group="YEAR")
res
plot_tbl_basic(df=tmp,target="EWR_0_humid",group="YEAR")
res <- basicr::basicr(df=tmp,target="EWR_0_humid",group="MONTH")
res
plot_tbl_basic(df=tmp,target="EWR_0_humid",group="MONTH")
res <- basicr::basicr(df=tmp,target="NEWR_0_humidO2_7",group="WDAY")
res
plot_tbl_basic(df=tmp,target="EWR_0_humid",group="WDAY")
res <- basicr::basicr(df=tmp,target="EWR_0_humid",group="HOUR")
res
plot_tbl_basic(df=tmp,target="EWR_0_humid",group="HOUR")
# temperature
res <- basicr::basicr(df=tmp,target="EWR_0_temp")
res
res <- basicr::basicr(df=tmp,target="EWR_0_temp",group="YEAR")
res
plot_tbl_basic(df=tmp,target="EWR_0_temp",group="YEAR")
res <- basicr::basicr(df=tmp,target="EWR_0_temp",group="MONTH")
res
plot_tbl_basic(df=tmp,target="EWR_0_temp",group="MONTH")
res <- basicr::basicr(df=tmp,target="EWR_0_temp",group="WDAY")
res
plot_tbl_basic(df=tmp,target="EWR_0_temp",group="WDAY")
res <- basicr::basicr(df=tmp,target="EWR_0_temp",group="HOUR")
res
plot_tbl_basic(df=tmp,target="EWR_0_temp",group="HOUR")
```
---
title: "luft"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{luft}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
library(basicr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```
## Basic analysis on a client dataset.
```R
fromDate <- "2016/11/01 00:00:00"
toDate <- "2016/11/5 00:00:00"
timeResolution <- "hourly"
precision <- "hourly"
# get luftkvalitet data
luft <- friendlyr::ts(session_name="luftlyr",username="*****",password="*****",
fromDate=fromDate,toDate=toDate,precision=precision,timeResolution=timeResolution,
element_id=c("NO2"),location="oslo,norway")
plot(luft,target="NO2_7",DESKTOP=TRUE)
res <- basicr::basicr(dataset=luft,target="NO2_7",group="none")
res
res <- basicr::basicr(dataset=luft,target="NO2_7",group="HOUR")
res
res <- basicr::basicr(dataset=luft,target="NO2_7",group="WDAY")
res
res <- basicr::basicr(dataset=luft,target="NO2_7",group="MONTH")
res
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment