Search and remove values at given indices, which can be numeric or character or both. If any given index is invalid, an error is signaled. Indices can be numbers or names or both.

delete_at(.x, ...)

ref_delete_at(.x, ...)

# S3 method for Container
delete_at(.x, ...)

# S3 method for Container
ref_delete_at(.x, ...)

# S3 method for dict.table
delete_at(.x, ...)

# S3 method for dict.table
ref_delete_at(.x, ...)

Arguments

.x

any R object.

...

indices at which values are to be deleted.

Value

For Container, an object of class Container (or one of the respective derived classes).

For dict.table, an object of class dict.table.

Examples


co = container(a = 1, b = 2, 3)
delete_at(co, "a", "b")          # [3]
#> [3]
delete_at(co, 1:2)               # [3]
#> [3]
delete_at(co, "a", 3)            # [b = 2]
#> [b = 2]
try({
delete_at(co, 4)                 # index out of range
delete_at(co, "x")               # names(s) not found: 'x'
})
#> Error : index out of range (length = 3): 4

dit = as.dict.table(head(sleep))
dit
#> <dict.table> with 6 rows and 3 columns
#>    extra group ID
#> 1:   0.7     1  1
#> 2:  -1.6     1  2
#> 3:  -0.2     1  3
#> 4:  -1.2     1  4
#> 5:  -0.1     1  5
#> 6:   3.4     1  6
delete_at(dit, "ID")
#> <dict.table> with 6 rows and 2 columns
#>    extra group
#> 1:   0.7     1
#> 2:  -1.6     1
#> 3:  -0.2     1
#> 4:  -1.2     1
#> 5:  -0.1     1
#> 6:   3.4     1
delete_at(dit, "ID", 1)
#> <dict.table> with 6 rows and 1 column
#>    group
#> 1:     1
#> 2:     1
#> 3:     1
#> 4:     1
#> 5:     1
#> 6:     1
try({
 delete_at(dit, "foo")   # Column 'foo' not in dict.table
})
#> Error : column(s) not found: 'foo'