-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy path070_data_types.Rmd
executable file
·43 lines (26 loc) · 1.79 KB
/
070_data_types.Rmd
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
36
37
38
39
# Data types
All the basic data types and data structures provided by R are available in Rcpp. By using these data types, you can directly access the objects that exist in R.
## Vector and Matrix
Following seven data types are often used in R.
`logical` `integer` `numeric` `complex` `character` `Date` `POSIXct`
There are vector type and matrix types in Rcpp corresponding to those of R.
In this document, the word `Vector` and `Matrix` is used to specify all the vector and matrix types in Rcpp.
The table below presents the correspondence of data types between R/Rcpp/C++.
|Value | R vector|Rcpp vector|Rcpp matrix|Rcpp scalar|C++ scalar|
|:---:|:---:|:---:|:---:|:---:|:---:|
|Logical|`logical` |`LogicalVector`| `LogicalMatrix`| - |`bool`|
|Integer|`integer` |`IntegerVector`|`IntegerMatrix`|-|`int`|
|Real|`numeric` |`NumericVector`|`NumericMatrix`|-|`double`|
|Complex|`complex` |`ComplexVector`| `ComplexMatrix`|`Rcomplex`|`complex`|
|String|`character`|`CharacterVector` (`StringVector`)| `CharacterMatrix` (`StringMatrix`)|`String`|`string`|
|Date |`Date` |`DateVector`|-|`Date`|-|
|Datetime |`POSIXct` |`DatetimeVector`|-| `Datetime` | `time_t` |
## data.frame, list, S3, S4
Other than `Vector` and `Matrix`, There are several data structures in R such as data.frame, list, S3 class and S4 class. You can handle all of these data structures in Rcpp.
|R|Rcpp|
|:---:|:---:|
|`data.frame`|`DataFrame`|
|`list`|`List`|
|S3 class|`List`|
|S4 class|`S4`|
In Rcpp, `Vector`, `DataFrame`, `List` are all implemented as kinds of vectors. Namely, `Vector` is a vector that its elements are scalar values, `DataFrame` is a vector that its elements are `Vector`s, `List` is a vector that its elements are any kind of data types. Thus, `Vector`, `DataFrame`, `List` has many common member functions in Rcpp.