Title: | Incomplete Array with Arbitrary R Objects as Indices |
---|---|
Description: | The aim of the package is to create data objects which allow for accesses like x["test"] and x["test","test"]. |
Authors: | Sigbert Klinke [aut, cre] |
Maintainer: | Sigbert Klinke <[email protected]> |
License: | GPL-3 |
Version: | 0.1.1 |
Built: | 2024-11-19 05:40:49 UTC |
Source: | https://github.com/cran/listArray |
listArray
Operators acting on one element of a listArray
to extract or replace it.
## S3 method for class 'listArray' x[...] ## S3 replacement method for class 'listArray' x[...] <- value
## S3 method for class 'listArray' x[...] ## S3 replacement method for class 'listArray' x[...] <- value
x |
object from which to extract a element or in which to replace a element. |
... |
indices specifying the element to extract or replace. Indices can consist of any R Object. |
value |
value which replaces a |
Returns or sets the selected element.
l <- listArray() l[1] <- 1 l[1] # l[2,3] <- "test" l[2,3] # l[2:3] <- "vector" l[2:3] l[2,3] # l['iris'] <- iris head(l['iris']) # l[letters[1:5]] <- letters[1:5] l[letters[1:5]] # l[mean] <- mean l[mean](0:10)
l <- listArray() l[1] <- 1 l[1] # l[2,3] <- "test" l[2,3] # l[2:3] <- "vector" l[2:3] l[2,3] # l['iris'] <- iris head(l['iris']) # l[letters[1:5]] <- letters[1:5] l[letters[1:5]] # l[mean] <- mean l[mean](0:10)
Checks if a specific index exists
hasKey(x, ...)
hasKey(x, ...)
x |
listArray object |
... |
index to check |
logical: TRUE
index exists, FALSE
index exists not
l <- listArray() l[1] <- 1 hasKey(l, 1) l[2,3] <- "test" hasKey(l, 2, 3) l[2:3] <- "vector" hasKey(l, 2:3) l['iris'] <- iris hasKey(l, iris) # FALSE l[mean] <- mean hasKey(l, mean) # if you have not stored NULL objects in your listArray is.null(l[mean]) is.null(l[iris])
l <- listArray() l[1] <- 1 hasKey(l, 1) l[2,3] <- "test" hasKey(l, 2, 3) l[2:3] <- "vector" hasKey(l, 2:3) l['iris'] <- iris hasKey(l, iris) # FALSE l[mean] <- mean hasKey(l, mean) # if you have not stored NULL objects in your listArray is.null(l[mean]) is.null(l[iris])
Creates a character key from arbitray R objects. For more details see vignette("listArray")
.
key(...)
key(...)
... |
R objects |
a unique character key
key(1) key(2,3) key(1:3) key(mean) key('test') key(letters[1:5]) key(list(1)) key(iris)
key(1) key(2,3) key(1:3) key(mean) key('test') key(letters[1:5]) key(list(1)) key(iris)
dimnames
).Returns a list of indices as string, list or unique values (like dimnames
).
keys(x, type = "character")
keys(x, type = "character")
x |
listArray object |
type |
character: return the indices as string, list or unique values (default: |
Returns the indices as string, list or unique indices. If type
is
type="character"
a character vector with the retranslated indices
type="list"
as list of lists with the retranslated indices
type="names"
as list of lists with the retranslated unique(!) indices like dimnames
l <- listArray(matrix(1:9, 3, 3)) k <- keys(l) k # access object in listArray pos <- which(k=='3, 2') l[[pos]] # l["test"] <- "test" keys(l, 'c') # as keys(l) keys(l, 'l') keys(l, 'n') # Note that l['test'][3] will deliver NULL since the entry does not exist
l <- listArray(matrix(1:9, 3, 3)) k <- keys(l) k # access object in listArray pos <- which(k=='3, 2') l[[pos]] # l["test"] <- "test" keys(l, 'c') # as keys(l) keys(l, 'l') keys(l, 'n') # Note that l['test'][3] will deliver NULL since the entry does not exist
Creates either an empty listArray
object or a listArray
object from a vector, array or list.
See also vignette("listArray")
.
listArray(x, ...) ## Default S3 method: listArray(x, use.names = TRUE, ignore = NULL, env = FALSE, ...)
listArray(x, ...) ## Default S3 method: listArray(x, use.names = TRUE, ignore = NULL, env = FALSE, ...)
x |
vector, array or list |
... |
further arguments given to |
use.names |
logical: if the names from |
ignore |
values to ignore for the listArray object |
env |
logical: if the listArray creates a list or an environment (default: |
a listArray
object
# empty listArray l <- listArray() # listArray from a numerical vector v <- 1:5 l <- listArray(v) # listArray from a text vector v <- letters[1:5] l <- listArray(v) #' # listArray from a matrix m <- matrix(1:9, 3, 3) l <- listArray(m) #' # listArray from a list v <- as.list(1:5) l <- listArray(v)
# empty listArray l <- listArray() # listArray from a numerical vector v <- 1:5 l <- listArray(v) # listArray from a text vector v <- letters[1:5] l <- listArray(v) #' # listArray from a matrix m <- matrix(1:9, 3, 3) l <- listArray(m) #' # listArray from a list v <- as.list(1:5) l <- listArray(v)