Learn R Programming

container (version 1.0.5)

delete_at: Delete Elements at Indices Safely

Description

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.

Usage

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, ...)

Value

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

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

Arguments

.x

any R object.

...

indices at which values are to be deleted.

Examples

Run this code

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

dit = as.dict.table(head(sleep))
dit
delete_at(dit, "ID")
delete_at(dit, "ID", 1)
try({
 delete_at(dit, "foo")   # Column 'foo' not in dict.table
})

Run the code above in your browser using DataLab