basicr_on_data.luftkval.oslo10.Rmd 2.34 KB
Newer Older
jml's avatar
jml committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
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")

```