工廠方法
ChunkedArray$create()
工廠方法從各種 Arrays 或 R 向量實例化物件。chunked_array()
是它的別名。
方法
$length()
:此陣列包含的元素數量大小$chunk(i)
:依整數位置提取Array
分塊$nbytes()
:陣列元素消耗的總位元組數$as_vector()
:轉換為 R 向量$Slice(offset, length = NULL)
:使用指定的偏移量和長度,建構陣列的零複製切片。如果 length 為NULL
,則切片會延伸到陣列的末尾。$Take(i)
:傳回一個ChunkedArray
,其值位於整數i
給定的位置。如果i
是 ArrowArray
或ChunkedArray
,則在取得之前會被強制轉換為 R 向量。$Filter(i, keep_na = TRUE)
:傳回一個ChunkedArray
,其值位於邏輯向量或 Arrow 布林類型(Chunked)Array
i
為TRUE
的位置。$SortIndices(descending = FALSE)
:傳回一個整數位置的Array
,可用於以升序或降序重新排列ChunkedArray
$cast(target_type, safe = TRUE, options = cast_options(safe))
:變更陣列中的資料以更改其類型。$null_count
:陣列中空值的數量$chunks
:傳回Arrays
的列表$num_chunks
:ChunkedArray
中的整數分塊數$type
:資料的邏輯類型$View(type)
:使用給定的類型,建構此ChunkedArray
的零複製視圖。$Validate()
:執行任何驗證檢查,以確定陣列內部資料中明顯的不一致性。這可能是一項昂貴的檢查,可能為O(length)
範例
# Pass items into chunked_array as separate objects to create chunks
class_scores <- chunked_array(c(87, 88, 89), c(94, 93, 92), c(71, 72, 73))
class_scores$num_chunks
#> [1] 3
# When taking a Slice from a chunked_array, chunks are preserved
class_scores$Slice(2, length = 5)
#> ChunkedArray
#> <double>
#> [
#> [
#> 89
#> ],
#> [
#> 94,
#> 93,
#> 92
#> ],
#> [
#> 71
#> ]
#> ]
# You can combine Take and SortIndices to return a ChunkedArray with 1 chunk
# containing all values, ordered.
class_scores$Take(class_scores$SortIndices(descending = TRUE))
#> ChunkedArray
#> <double>
#> [
#> [
#> 94,
#> 93,
#> 92,
#> 89,
#> 88,
#> 87,
#> 73,
#> 72,
#> 71
#> ]
#> ]
# If you pass a list into chunked_array, you get a list of length 1
list_scores <- chunked_array(list(c(9.9, 9.6, 9.5), c(8.2, 8.3, 8.4), c(10.0, 9.9, 9.8)))
list_scores$num_chunks
#> [1] 1
# When constructing a ChunkedArray, the first chunk is used to infer type.
doubles <- chunked_array(c(1, 2, 3), c(5L, 6L, 7L))
doubles$type
#> Float64
#> double
# Concatenating chunked arrays returns a new chunked array containing all chunks
a <- chunked_array(c(1, 2), 3)
b <- chunked_array(c(4, 5), 6)
c(a, b)
#> ChunkedArray
#> <double>
#> [
#> [
#> 1,
#> 2
#> ],
#> [
#> 3
#> ],
#> [
#> 4,
#> 5
#> ],
#> [
#> 6
#> ]
#> ]