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


## Description
jml's avatar
jml committed
5
Compute basic statistics on a tbl_friendlyts table:
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
6

jml's avatar
jml committed
7
8
9
10
11
1. Mean, standard-deviation, IQR. min, max,...
2. On different groups: year, month, weekday, hour,minute, second.


## Installation
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
12
13

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

jml's avatar
jml committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
### get 'weather' dataset from 'nycflights13'
```R
#install.packages("nycflights13")
library(nycflights13)
data(weather)

# There are some duplicated rows, I assume there were a maximum of 2 stations for each location.
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
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
40
41

```R
jml's avatar
jml committed
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
85
86
87
88
89
90
91
92
93
94
95
# 'weather' as friendlyts

# devtools::install_git("https://git.nilu.no/rfriendlyts/friendlyts.git")
tmp <- friendlyts::friendlyts(df=tmp,date_col="time_hour",date_type="posixlt",tzone="EST")

tmp
```

### 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")


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