Oliver Nakoinz, Lizzie Scholtus, Néhémie Strupler
Block 0: Introduction to R
R is a language and environment for statistical computing and graphics
- flexible
- impressive
- badly documented
##################################################################
## Didactic R-Script for Modelling Summer School
## ===============================================================
## Project: Modelling Summer School
## Author: O. Nakoinz, C. Filet & F. Faupel
## Version: 01
## Date of last changes: 10.09.2018
## Data: some.data
## Author of data: author.data
## Purpose: didactic
## Content: 1. preparation, 2. data import, ...
## Description: The script include ...
## Licence data: -
## Licence Script: GPL (http://www.gnu.org/licenses/gpl-3.0.html)
##################################################################
UTF-8
.<-
to assign not =
Do not try remembering all details, focus on the most important aspects
Knowledge means, knowing where it is written. (attributed to Albert Einstein)
Educated is who knows where to find what he does not know. (attributed to Georg Simmel)
## [1] 8
## [1] 2
## [1] 15
## [1] 1.666667
## [1] 125
## [1] 2
## [1] 1
Operator | Description |
---|---|
+ | addition |
- | subtraction |
* | multiplication |
/ | division |
^ or ** | exponentiation |
x %% y | modulus (x mod y) 5 %% 2 is 1 |
x %/% y | integer division 5 %/% 2 is 2 |
read and analyze code!
## [1] FALSE
## [1] TRUE
## [1] TRUE
## [1] TRUE
## [1] FALSE
## [1] FALSE
## [1] FALSE
## [1] TRUE
## [1] FALSE
## [1] TRUE
Operator | Description |
---|---|
== | exactly equal to |
!= | not equal to |
< | less than |
<= | less than or equal to |
> | greater than |
>= | greater than or equal to |
!x | Not x |
x | y |
x & y | x AND y |
isTRUE(x) | test if X is TRUE |
## [1] 5
## [1] 0.001592653
## [1] 3.218876
## [1] 1.39794
## [1] 345.3356
## [1] 2
## [1] 3
## [1] 2
## [1] 0.001592653
## [1] 0.1411200 0.9906074
here
(Müller 2020) provides functions for dealing with the pathpandoc xxfilterxx -s -f markdown -t html $infile.md -o $outfile.html
xxx
# 1st level header
## 2nd level header
**bolt**
*italic*
[link](https://en.wikipedia.org/wiki/Markdown)
![image](xxx.svg)
- list item
- list item
(just ident)1. numbered list item
$a_3 = \sqrt{a_1 + a_2}$
footnote^[fn1]
[fn1]: footnote text
(anywhere in the document)superscript^2^
`x <- 5`
block quotes:
> block quotes
a | b | c |
---|---|---|
1 | 2 | 3 |
2 | 3 | 4 |
| a| b| c|
|--:|--:|--:|
| 1| 2| 3|
| 2| 3| 4|
remedy
provides gui access to markdownA Markdown file starts with a YAML header.
---
title: "Untitled"
output: html_document
---
---
title: "Untitled"
author: '[Prof. Dr. Oliver Nakoinz](http://oliver.nakoinz.gitlab.io/OliverNakoinz/)'
date: "WS 2020/2021"
bibliography: ../7lib/71citations/lit.bib
csl: ../7lib/72csl/iso690-author-date-cs.csl
lang: de-DE
otherlangs: en-GB
output:
slidy_presentation:
highlight: tango
pandoc_args:
- --css
- stycss/styles.css
footer: "Oliver Nakoinz"
df_print: kable
fontsize: 14pt
font-family: 'Helvetica'
widescreen: true
---
@book{xie2018r,
title = {R Markdown: The Definitive Guide},
author = {Xie, Y. and Allaire, J.J. and Grolemund, G.},
isbn = {9781138359338},
series = {Chapman and Hall/CRC the R Series},
url = {https://bookdown.org/yihui/rmarkdown/},
year = {2018},
publisher = {Taylor \& Francis, CRC Press}
}
```{r code chunks name}
a <- c(2, 3, 4)
sum(a)
```
Markdown
| a| b| c|
|--:|--:|--:|
| 1| 2| 3|
| 2| 3| 4|
a | b | c |
---|---|---|
1 | 2 | 3 |
2 | 3 | 4 |
Start new script with File>RMarkdown
presentations: slidy, iosslides, beamer, PowerPoint
books bookdown: Xie (2021b)
articles: rticles Allaire, J. et al. (2021b)
further articles: rmdformats Barnier (2021)
A vector contains an ordered set of elements of the same type.
Vectors are defined with the function c
(for concatenate).
Vectors can be defined as sequence and many functions are available for manipulating vectors.
read and analyze code!
Parts of vectors (and other structures) can be addressed with indices.
Vectors can be passed as parameter to functions. Some functions return information on the vectors.
x <- c(3, 5, 2, 2, 5, 8, 5, 2)
y <- c(6, 7, 2, 4, 5, 2, 9, 1)
zx <- matrix(x, 2, 4)
zy <- matrix(y, 2, 4)
zx + zy
## [,1] [,2] [,3] [,4]
## [1,] 9 4 10 14
## [2,] 12 6 10 3
(rarely used)
## , , 1
##
## [,1] [,2]
## [1,] 1 4
## [2,] 2 5
## [3,] 3 6
##
## , , 2
##
## [,1] [,2]
## [1,] 7 10
## [2,] 8 11
## [3,] 9 12
## [1] 3 5 2 2 5 8 5 2
## [1] 3 5 2 2 5 8 5 2
x | y |
---|---|
3 | 6 |
## [1] 3 4 8
## [1] Nicole Sabire Clemens Jos Nicole
## Levels: Clemens Jos Nicole Sabire
## [1] 3 4 1 2 3
## attr(,"levels")
## [1] "Clemens" "Jos" "Nicole" "Sabire"
## [1] "Clemens" "Jos" "Nicole" "Sabire"
## [1] "Sabire"
[rows, columns]
## [1] 0.14112
## [1] 4
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## x 3 5 2 2 5 8 5 2
## y 6 7 2 4 5 2 9 1
## x y
## [1,] 3 6
## [2,] 5 7
## [3,] 2 2
## [4,] 2 4
## [5,] 5 5
## [6,] 8 2
## [7,] 5 9
## [8,] 2 1
## [1] 7.605434 6.291699 8.035295 5.382489 5.543796
## num [1:8] 3 5 2 2 5 8 5 2
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2 2 4 4 5 8
## [1] "a" "add5" "df" "f" "l" "wd_lin"
## [7] "wd_win" "x" "x_rev" "x_revsort" "x_sort" "x_sortdec"
## [13] "y" "z" "z2" "z3" "zx" "zy"
## [1] "MOSAICdata_block0_1.html"
## [2] "MOSAICdata_block0_1.rmd"
## [3] "MOSAICdata_block0_1b.html"
## [4] "MOSAICdata_block0_1b.rmd"
## [5] "MOSAICdata_block0_2.html"
## [6] "MOSAICdata_block0_2.rmd"
## [7] "MOSAICdata_block0_2b.html"
## [8] "MOSAICdata_block0_2b.rmd"
## [9] "MOSAICdata_block0_3.html"
## [10] "MOSAICdata_block0_3.rmd"
## [11] "MOSAICdata_block0_3b.html"
## [12] "MOSAICdata_block0_3b.rmd"
## [13] "Rintro1.Rmd"
## [14] "Rintro2.Rmd"
## [15] "s01.html"
## [16] "s01.Rmd"
## [17] "s02.html"
## [18] "s02.Rmd"
## [19] "s03.html"
## [20] "s03.Rmd"
## [21] "s04.html"
## [22] "s04.Rmd"
## [23] "s05.html"
## [24] "s05.Rmd"
## [25] "s06.html"
## [26] "s06.Rmd"
## [27] "s07.html"
## [28] "s07.Rmd"
## [29] "s08.html"
## [30] "s08.Rmd"
## [31] "s09.html"
## [32] "s09.Rmd"
## [33] "s1_Kursfolienvorlage_Einfuehrung.Rmd"
## [34] "s1_Kursfolienvorlage.Rmd"
## [35] "s10.html"
## [36] "s10.Rmd"
## [37] "s11.html"
## [38] "s11.Rmd"
## [39] "s12.Rmd"
## [40] "stycss"
## [41] "titelfolie.html"
## [42] "titelfolie.pdf"
## [43] "titelfolie.Rmd"
a_v
with some numbers: 4.5, 6.2, 6.4, 7.9 and 7.3b_v
with fife names (perhaps participants)c_m
with 12 cells and random contentd_df
with fictive names and sizealle_l
of all elements created beforea_v
b_v
alle_l
a_v
fn1↩︎