Movatterモバイル変換


[0]ホーム

URL:


Skip to contents

Array Classes

Source:R/array.R
array-class.Rd

AnArray is an immutable data array with some logical typeand some length. Most logical types are contained in the baseArray class; there are also subclasses forDictionaryArray,ListArray,andStructArray.

Factory

TheArray$create() factory method instantiates anArray andtakes the following arguments:

  • x: an R vector, list, ordata.frame

  • type: an optionaldata type forx. If omitted, the typewill be inferred from the data.

Array$create() will return the appropriate subclass ofArray, such asDictionaryArray when given an R factor.

To compose aDictionaryArray directly, callDictionaryArray$create(),which takes two arguments:

  • x: an R vector orArray of integers for the dictionary indices

  • dict: an R vector orArray of dictionary values (like R factor levelsbut not limited to strings only)

Usage

a<- Array$create(x)length(a)print(a)a== a

Methods

  • $IsNull(i): Return true if value at index is null. Does not boundscheck

  • $IsValid(i): Return true if value at index is valid. Does not boundscheck

  • $length(): Size in the number of elements this array contains

  • $nbytes(): Total number of bytes consumed by the elements of the array

  • $offset: A relative position into another array's data, to enable zero-copy slicing

  • $null_count: The number of null entries in the array

  • $type: logical type of data

  • $type_id(): type id

  • $Equals(other) : is this array equal toother

  • $ApproxEquals(other) :

  • $Diff(other) : return a string expressing the difference between two arrays

  • $data(): return the underlyingArrayData

  • $as_vector(): convert to an R vector

  • $ToString(): string representation of the array

  • $Slice(offset, length = NULL): Construct a zero-copy slice of the arraywith the indicated offset and length. If length isNULL, the slice goesuntil the end of the array.

  • $Take(i): return anArray with values at positions given by integers(R vector or Array Array)i.

  • $Filter(i, keep_na = TRUE): return anArray with values at positions where logicalvector (or Arrow boolean Array)i isTRUE.

  • $SortIndices(descending = FALSE): return anArray of integer positions that can beused to rearrange theArray in ascending or descending order

  • $RangeEquals(other, start_idx, end_idx, other_start_idx) :

  • $cast(target_type, safe = TRUE, options = cast_options(safe)): Alter thedata in the array to change its type.

  • $View(type): Construct a zero-copy view of this array with the given type.

  • $Validate() : Perform any validation checks to determine obvious inconsistencieswithin the array's internal data. This can be an expensive check, potentiallyO(length)

Examples

my_array<-Array$create(1:10)my_array$type#> Int32#> int32my_array$cast(int8())#> Array#> <int8>#> [#>   1,#>   2,#>   3,#>   4,#>   5,#>   6,#>   7,#>   8,#>   9,#>   10#> ]# Check if value is null; zero-indexedna_array<-Array$create(c(1:5,NA))na_array$IsNull(0)#> [1] FALSEna_array$IsNull(5)#> [1] TRUEna_array$IsValid(5)#> [1] FALSEna_array$null_count#> [1] 1# zero-copy slicing; the offset of the new Array will be the same as the index passed to $Slicenew_array<-na_array$Slice(5)new_array$offset#> [1] 5# Compare 2 arraysna_array2<-na_arrayna_array2==na_array# element-wise comparison#> Array#> <bool>#> [#>   true,#>   true,#>   true,#>   true,#>   true,#>   null#> ]na_array2$Equals(na_array)# overall comparison#> [1] TRUE

[8]ページ先頭

©2009-2025 Movatter.jp