• rray_duplicate_any(): returns a logical with the same shape and type as x except over the axes, which will be reduced to length 1. This function detects the presence of any duplicated values along the axes.

  • rray_duplicate_detect(): returns a logical with the same shape and type as x describing if that element of x is duplicated elsewhere.

  • rray_duplicate_id(): returns an integer with the same shape and type as x giving the location of the first occurrence of the value.

rray_duplicate_any(x, axes = NULL)

rray_duplicate_detect(x, axes = NULL)

rray_duplicate_id(x, axes = NULL)

Arguments

x

A vector, matrix, array, or rray.

axes

An integer vector. The default of NULL looks for duplicates over all axes.

Value

See the description for return value details.

See also

rray_unique() for functions that work with the dual of duplicated values: unique values.

vctrs::vec_duplicate_any() for functions that detect duplicates among any type of vector object.

Examples

x <- rray(c(1, 1, 2, 2), c(2, 2)) x <- rray_set_row_names(x, c("r1", "r2")) x <- rray_set_col_names(x, c("c1", "c2")) # Are there duplicates along the rows? rray_duplicate_any(x, 1L)
#> <rray<lgl>[,2][1]> #> c1 c2 #> [1,] TRUE TRUE
# Are there duplicates along the columns? rray_duplicate_any(x, 2L)
#> <rray<lgl>[,1][2]> #> [,1] #> r1 FALSE #> r2 FALSE
# Create a 3d version of x # where the columns are not unique y <- rray_expand(x, 1) # Along the rows, all the values are unique... rray_duplicate_any(y, 1L)
#> <rray<lgl>[,2,2][1]> #> , , c1 #> #> r1 r2 #> [1,] FALSE FALSE #> #> , , c2 #> #> r1 r2 #> [1,] FALSE FALSE #>
# ...but along the columns there are duplicates rray_duplicate_any(y, 2L)
#> <rray<lgl>[,1,2][1]> #> , , c1 #> #> [,1] #> [1,] TRUE #> #> , , c2 #> #> [,1] #> [1,] TRUE #>
# --------------------------------------------------------------------------- z <- rray(c(1, 1, 2, 3, 1, 4, 5, 6), c(2, 2, 2)) # rray_duplicate_detect() looks for any # duplicates along the axes of interest # and returns `TRUE` wherever a duplicate is found # (including the first location) rray_duplicate_detect(z, 1)
#> <rray<lgl>[,2,2][2]> #> , , 1 #> #> [,1] [,2] #> [1,] TRUE FALSE #> [2,] TRUE FALSE #> #> , , 2 #> #> [,1] [,2] #> [1,] FALSE FALSE #> [2,] FALSE FALSE #>
# Positions 1 and 5 are the same! rray_duplicate_detect(z, 3)
#> <rray<lgl>[,2,2][2]> #> , , 1 #> #> [,1] [,2] #> [1,] TRUE FALSE #> [2,] FALSE FALSE #> #> , , 2 #> #> [,1] [,2] #> [1,] TRUE FALSE #> [2,] FALSE FALSE #>
# --------------------------------------------------------------------------- # rray_duplicate_id() returns the location # of the first occurance along each axis. # Compare to rray_duplicate_detect()! rray_duplicate_detect(z, 1)
#> <rray<lgl>[,2,2][2]> #> , , 1 #> #> [,1] [,2] #> [1,] TRUE FALSE #> [2,] TRUE FALSE #> #> , , 2 #> #> [,1] [,2] #> [1,] FALSE FALSE #> [2,] FALSE FALSE #>
rray_duplicate_id(z, 1)
#> <rray<int>[,2,2][2]> #> , , 1 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 2 #> #> , , 2 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 2 2 #>