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


## Description

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
6
7
8
9
10
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
11
12
13


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

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

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

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

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

jml's avatar
jml committed
42
43
```

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

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

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

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

```

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

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

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

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

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

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

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

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

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

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

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

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