basicr_on_weather_from_nycflights13.Rmd 2.48 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
---
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)

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

jml's avatar
jml committed
36
37
38
```

### 'weather' as friendlyts
jml's avatar
jml committed
39

jml's avatar
jml committed
40
```R
jml's avatar
jml committed
41
# 'weather' as friendlyts
jml's avatar
jml committed
42
43
44

devtools::install_git("https://git.nilu.no/rfriendlyts/friendlyts.git")

jml's avatar
jml committed
45
46
47
48
49
50
51
52
53
tmp <- friendlyts::friendlyts(df=tmp,date_col="time_hour",date_type="posixlt",tzone="EST")

```

### Basic analysis.
```R
names(tmp)

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

Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
57
res <- basicr::basic_info(df=tmp,target="EWR_0_humid",group="YEAR")
jml's avatar
jml committed
58
res
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
59
basicr::plot_tbl_basic(df=tmp,target="EWR_0_humid",group="YEAR")
jml's avatar
jml committed
60

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

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

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

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

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

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

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

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

```