工厂
ChunkedArray$create() 工厂方法从各种数组或 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)Arrayi为TRUE的位置。$SortIndices(descending = FALSE):返回一个整数位置的Array,可用于按升序或降序重新排列ChunkedArray$cast(target_type, safe = TRUE, options = cast_options(safe)):更改数组中的数据以更改其类型。$null_count:数组中的空条目数$chunks:返回Array列表$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
#> ]
#> ]