2015-12-17 07:22:03 +08:00
|
|
|
---
|
2015-12-17 06:41:08 +08:00
|
|
|
layout: default
|
2015-12-17 07:22:03 +08:00
|
|
|
title: Data structures
|
|
|
|
---
|
2015-12-17 06:41:08 +08:00
|
|
|
|
2015-12-12 02:34:20 +08:00
|
|
|
# Data structures
|
2015-12-06 22:02:29 +08:00
|
|
|
|
2015-12-12 02:34:20 +08:00
|
|
|
Might be quite brief.
|
2015-12-06 22:02:29 +08:00
|
|
|
|
2016-01-21 23:51:02 +08:00
|
|
|
Atomic vectors and lists + data frames.
|
2015-12-06 22:02:29 +08:00
|
|
|
|
2016-01-21 23:51:02 +08:00
|
|
|
Most important data types:
|
2015-12-06 22:02:29 +08:00
|
|
|
|
2016-01-21 23:51:02 +08:00
|
|
|
* logical
|
|
|
|
* integer & double
|
|
|
|
* character
|
|
|
|
* date
|
|
|
|
* date time
|
|
|
|
* factor
|
|
|
|
|
|
|
|
<http://adv-r.had.co.nz/OO-essentials.html>
|
|
|
|
|
|
|
|
Every vector has three key properties:
|
|
|
|
|
|
|
|
1. Type: e.g. integer, double, list. Retrieve with `typeof()`.
|
|
|
|
2. Length. Retrieve with `length()`
|
|
|
|
3. Attributes. A named of list of additional metadata. With the `class`
|
|
|
|
attribute used to build more complex data structure (like factors and
|
|
|
|
dates) up from simpler components. Get with `attributes()`.
|
|
|
|
|
|
|
|
## Atomic vectors
|
|
|
|
|
|
|
|
### Doubles
|
|
|
|
|
|
|
|
```{r}
|
|
|
|
sqrt(2) ^ 2 - 2
|
|
|
|
|
|
|
|
0/0
|
|
|
|
1/0
|
|
|
|
-1/0
|
|
|
|
|
|
|
|
mean(numeric())
|
|
|
|
```
|
|
|
|
|
|
|
|
## Non-atomic vectors
|
|
|
|
|
|
|
|
`class()`
|
|
|
|
|
|
|
|
### Factors
|
2015-12-06 22:02:29 +08:00
|
|
|
|
|
|
|
(Since won't get a chapter of their own)
|
|
|
|
|
2016-01-21 23:51:02 +08:00
|
|
|
### Dates
|
|
|
|
|
|
|
|
### Date times
|
|
|
|
|
|
|
|
## Lists
|
|
|
|
|
|
|
|
## Data frames
|
|
|
|
|
2015-12-06 22:02:29 +08:00
|
|
|
## Subsetting
|
|
|
|
|
|
|
|
Not sure where else this should be covered.
|