list
list
sdata.frame
list
Tidy
-Format für Datenvector
# printe baselbasel
## # A tibble: 10,000 × 20## id geschlecht alter groesse gewicht## <dbl> <chr> <dbl> <dbl> <dbl>## 1 1 W 44 174 NA ## 2 2 M 65 180 85.6## 3 3 M 31 168 53.9## 4 4 M 31 166. 105 ## 5 5 M 24 180. 102. ## # … with 9,995 more rows
# Zeige den data frame in neuem tabView(basel)
$
# Extrahiere die Variable Alterbasel$alter
## [1] 44 65 31 31 24 59 48 53 50 62 73 53## [13] 38 26## [ reached getOption("max.print") -- omitted 9986 entries ]
# Extrahiere die Variable Bildungbasel$bildung
## [1] "obligatorisch" "sek III" ## [3] "sek III" "lehre" ## [5] "obligatorisch" "sek III" ## [7] "obligatorisch" "lehre" ## [9] "sek III" "lehre" ## [11] "sek III" "lehre" ## [13] "lehre" "obligatorisch"## [ reached getOption("max.print") -- omitted 9986 entries ]
$
# Teile die Variable einkommen durch 1000basel$einkommen <- basel$einkommen / 1000# zeige data framebasel
## # A tibble: 10,000 × 20## id geschlecht alter groesse gewicht## <dbl> <chr> <dbl> <dbl> <dbl>## 1 1 W 44 174 NA ## 2 2 M 65 180 85.6## 3 3 M 31 168 53.9## 4 4 M 31 166. 105 ## 5 5 M 24 180. 102. ## # … with 9,995 more rows
vector
numeric
# Extrahiere die Variable Alterbasel$alter
## [1] 44 65 31 31 24 59 48 53 50 62
# Zeige die Klasse von Alterclass(basel$alter)
## [1] "numeric"
# Ist Alter numericis.numeric(basel$alter)
## [1] TRUE
character
# Extrahiere die Variable Geschlechtbasel$geschlecht
## [1] "W" "M" "M" "M" "M" "M" "W" "W"
# Extrahiere die Variable Bildungbasel$bildung
## [1] "obligatorisch" "sek III" ## [3] "sek III" "lehre" ## [5] "obligatorisch" "sek III" ## [7] "obligatorisch" "lehre"
character
# Extrahiere die Variable Alterbasel$alter
## [1] 44 65 31 31 24 59 48 53 50 62
# Wandle Alter in character umas.character(basel$alter)
## [1] "44" "65" "31" "31" "24" "59" "48"## [8] "53" "50" "62"
logical
# Welche Werte in Geschlecht sind mbasel$geschlecht == "M"
## [1] FALSE TRUE TRUE TRUE TRUE TRUE## [7] FALSE FALSE TRUE FALSE
# Welche Werte in Alteer sind kleiner 30basel$alter < 50
## [1] TRUE FALSE TRUE TRUE TRUE FALSE## [7] TRUE FALSE FALSE FALSE
logical
Logische Operatoren
==
<
>
<=
>=
&
&&
|
||
[ ]
# Extrahiere die Variable Alteralter <- basel$alteralter
## [1] 44 65 31 31 24 59 48 53 50 62
# Extrahiere zweiten Wertalter[2]
## [1] 65
# Ändere zweiten Wertalter[2] <- 100alter
Mehr Info hier.
|
|
|
# Lese Basel Datensatz einbasel <- read_csv("1_Data/basel.csv")# Benutze expliziten Delimiterbasel <- read_delim("1_Data/basel.csv", delim = ",")basel
## # A tibble: 10,000 × 20## id geschlecht alter groesse## <dbl> <chr> <dbl> <dbl>## 1 1 f 87 165 ## 2 2 m 54 175.## 3 3 f 34 147.## 4 4 m 31 166.## 5 5 m 24 180.## # … with 9,995 more rows
# Lese Basel Datensatz einbasel <- read_csv("1_Data/basel.csv")# Benutze expliziten Delimiterbasel <- read_delim("1_Data/basel.csv", delim = ",")basel
## # A tibble: 10,000 × 20## id geschlecht alter groesse## <dbl> <chr> <dbl> <dbl>## 1 1 f 87 165 ## 2 2 m 54 175.## 3 3 f 34 147.## 4 4 m 31 166.## 5 5 m 24 180.## # … with 9,995 more rows
# Lese Basel Datensatz einbasel <- read_csv("1_Data/basel.csv")
## Rows: 10000 Columns: 20
## ── Column specification ────────────────## Delimiter: ","## chr (5): geschlecht, bildung, konfe...## dbl (15): id, alter, groesse, gewich...
## ## ℹ Use `spec()` to retrieve the full column specification for this data.## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Manchmal ist es nötig readr
etwas auf die Sprünge zu helfen, damit
# Setze Symbol für fehlende Wertebasel <- read_csv("1_Data/basel.csv", na = c('NA'))# Re-inferiere Datentypenbasel <- type_convert(basel)
# Verbinge mit MySQL Datenbankcon <- dbConnect(MySQL(), user='studiech_rbootca', password='Du*5hA+7NU:8T', dbname='studiech_rbootcamp', host='studie.ch', port = 3306)# Zeige TabellendbListTables(con)
## [1] "basel"
# Extrahiere Tabelle Customersbasel <- tbl(con, "basel")basel
## # Source: table<basel> [?? x 20]## # Database: mysql 5.7.26-log-cll-lve## # [@studie.ch:/studiech_rbootcamp]## id geschlecht alter_jahre groesse## <dbl> <chr> <dbl> <dbl>## 1 1 f 87 165 ## 2 2 m 54 175.## 3 3 f 34 147.## 4 4 m 31 166.## 5 5 m 24 180.## # … with more rows
# Extrahiere Tabelle Customersbasel <- tbl(con, "basel")# Extrahiere CompanyNamer Variablebasel %>% pull(konfession)
## [1] "katholisch" "konfessionslos"## [3] "konfessionslos" "katholisch" ## [5] "katholisch" NA ## [7] "konfessionslos" "katholisch" ## [9] "konfessionslos" "andere" ## [ reached getOption("max.print") -- omitted 9990 entries ]
# Tabelle laden von Wikipedia (mit xml2 und rvest)read_html("https://en.wikipedia.org/wiki/R_(programming_language)") %>% html_node(xpath = '//*[@id="mw-content-text"]/div/table[2]') %>% html_table() %>% as_tibble()
## # A tibble: 22 × 3## Release Date Description ## <chr> <chr> <chr> ## 1 0.16 "" "This is the last alpha version developed primarily by Ihaka and G…## 2 0.49 "1997-04-2… "This is the oldest source release which is currently available on…## 3 0.60 "1997-12-0… "R becomes an official part of the GNU Project. The code is hosted…## 4 0.65.1 "1999-10-0… "First versions of update.packages and install.packages functions …## 5 1.0 "2000-02-2… "Considered by its developers stable enough for production use.[57…## 6 1.4 "2001-12-1… "S4 methods are introduced and the first version for Mac OS X is m…## 7 1.8 "2003-10-0… "Introduced a flexible condition handling mechanism for signalling…## 8 2.0 "2004-10-0… "Introduced lazy loading, which enables fast loading of data with …## 9 2.1 "2005-04-1… "Support for UTF-8 encoding, and the beginnings of internationaliz…## 10 2.6.2 "2008-02-0… "Last version to support Windows 95, 98, Me and NT 4.0[58]" ## # … with 12 more rows
readr
# read fixed width files (can be fast)data <- read_fwf(file, ...)# read Apache style log filesdata <- read_log(file, ...)
haven
# read SAS's .sas7bat and sas7bcat filesdata <- read_sas(file, ...)# read SPSS's .sav filesdata <- read_sav(file, ...)# etc
readxl
# read Excel's .xls and xlsx filesdata <- read_excel(file, ...)
# Read Matlab .mat filesdata <- R.matlab::readMat(file, ...)# Read and wrangle .xml and .htmldata <- XML::xmlParseParse(file, ...)# from package jsonlite: read .json filesdata <- jsonlite::read_json(file, ...)
list
list
sdata.frame
list
Tidy
-Format für Datenvector
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |