4 创建 Arrow 对象

4.1 從 R 對象建立 Arrow 物件

您希望將 R 中的現有向量轉換為箭頭陣列物件。

4.1.1 解决方案

# Create an example vector
score = c(99, 97, 99)

# Convert to Arrow Array
score_array <- Array$create(score)

# View Array
score_array
## Array
## <double>
## [
##   99,
##   97,
##   99
## ]

4.2 從 R 對象建立 Arrow 表格

您希望將 R 中的現有資料框轉換為箭頭表格物件。

4.2.1 解决方案

# Create an example data frame
my_tibble <- tibble::tibble(group = c("A", "B", "C"), score = c(99, 97, 99))
# Convert to Arrow Table
my_table <- arrow_table(my_tibble)
# View table
my_table
## Table
## 3 rows x 2 columns
## $group <string>
## $score <double>

4.3 檢視 Arrow Table 或 RecordBatch 的內容

您想要檢視 Arrow Table 或 RecordBatch 的內容。

4.3.1 解決方案

# View Table
dplyr::collect(my_table)
## # A tibble: 3 × 2
##   group score
##   <chr> <dbl>
## 1 A        99
## 2 B        97
## 3 C        99

4.4 手動使用 R 物件建立 RecordBatch。

您想要將 R 中現有的資料框轉成 Arrow RecordBatch 物件。

4.4.1 解決方案

# Create an example data frame
my_tibble <- tibble::tibble(group = c("A", "B", "C"), score = c(99, 97, 99))
# Convert to Arrow RecordBatch
my_record_batch <- record_batch(my_tibble)
# View RecordBatch
my_record_batch
## RecordBatch
## 3 rows x 2 columns
## $group <string>
## $score <double>