basicr_on_weather_from_nycflights13.Rmd 2.38 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
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
tmp <- friendlyts::friendlyts(df=tmp,date_col="time_hour",date_type="posixlt",tzone="EST")

```

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


```