README.md 2.56 KB
Newer Older
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
1
2
3
4
5
# basicr


## Description

jml's avatar
jml committed
6
7
8
9
10
11
Basic information from a tbl_friendlyts data.frame:

- Mean, standard-deviation, IQR. min, max,... on different groups: year, month, weekday, hour, minute, second.
- Timeseries of basic information.
- L-moments.
- Plots.
jml's avatar
jml committed
12
13
14


## Installation
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
15
16

```R
jml's avatar
jml committed
17
18
library("devtools")
devtools::install_git("https://git.nilu.no/rdiagnosis/basicr.git")
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
19
```
jml's avatar
jml committed
20
## Usage
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
21

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
22
23
24
### Basic analysis on 'weather' from 'nycflights13' package.

#### get dataset
jml's avatar
jml committed
25
26
27
28
29
```R
#install.packages("nycflights13")
library(nycflights13)
data(weather)

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
30
# There are some duplicated rows, I assume there were a maximum of 2 stations.
jml's avatar
jml committed
31
32
33
34
35
36
37
38
39
40
41
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')
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
42

jml's avatar
jml committed
43
44
```

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
45
#### 'weather' as friendlyts
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
46
47

```R
jml's avatar
jml committed
48
49
# 'weather' as friendlyts

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
50
51
devtools::install_git("https://git.nilu.no/rfriendlyts/friendlyts.git")

jml's avatar
jml committed
52
53
54
55
tmp <- friendlyts::friendlyts(df=tmp,date_col="time_hour",date_type="posixlt",tzone="EST")

```

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
56
#### Basic analysis.
jml's avatar
jml committed
57
58
59
60
```R
names(tmp)

# Relative humidity
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
61
res <- basicr::basic_info(df=tmp,target="EWR_0_humid")
jml's avatar
jml committed
62
63
res

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
64
res <- basicr::basic_info(df=tmp,target="EWR_0_humid",group="YEAR")
jml's avatar
jml committed
65
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
66
basicr::plot_tbl_basic(df=tmp,target="EWR_0_humid",group="YEAR")
jml's avatar
jml committed
67

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
68
res <- basicr::basic_info(df=tmp,target="EWR_0_humid",group="MONTH")
jml's avatar
jml committed
69
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
70
basicr::plot_tbl_basic(df=tmp,target="EWR_0_humid",group="MONTH")
jml's avatar
jml committed
71

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
72
res <- basicr::basic_info(df=tmp,target="NEWR_0_humidO2_7",group="WDAY")
jml's avatar
jml committed
73
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
74
basicr::plot_tbl_basic(df=tmp,target="EWR_0_humid",group="WDAY")
jml's avatar
jml committed
75

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
76
res <- basicr::basic_info(df=tmp,target="EWR_0_humid",group="HOUR")
jml's avatar
jml committed
77
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
78
basicr::plot_tbl_basic(df=tmp,target="EWR_0_humid",group="HOUR")
jml's avatar
jml committed
79
80

# temperature
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
81
res <- basicr::basic_info(df=tmp,target="EWR_0_temp")
jml's avatar
jml committed
82
83
res

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
84
res <- basicr::basic_info(df=tmp,target="EWR_0_temp",group="YEAR")
jml's avatar
jml committed
85
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
86
basicr::plot_tbl_basic(df=tmp,target="EWR_0_temp",group="YEAR")
jml's avatar
jml committed
87

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
88
res <- basicr::basic_info(df=tmp,target="EWR_0_temp",group="MONTH")
jml's avatar
jml committed
89
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
90
basicr::plot_tbl_basic(df=tmp,target="EWR_0_temp",group="MONTH")
jml's avatar
jml committed
91

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
92
res <- basicr::basic_info(df=tmp,target="EWR_0_temp",group="WDAY")
jml's avatar
jml committed
93
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
94
basicr::plot_tbl_basic(df=tmp,target="EWR_0_temp",group="WDAY")
jml's avatar
jml committed
95

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
96
res <- basicr::basic_info(df=tmp,target="EWR_0_temp",group="HOUR")
jml's avatar
jml committed
97
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
98
basicr::plot_tbl_basic(df=tmp,target="EWR_0_temp",group="HOUR")
jml's avatar
jml committed
99

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
100
```