Learn R Programming

lambda.tools (version 1.0.9)

anynames: Get the names of a data structure. This attempts to create some polymorphism around lists, vectors, and data.frames

Description

This function gets the useful names of a data structure. This attempts to create some polymorphism around lists, vectors, and data.frames.

Arguments

data
Any indexable data structure

Value

Returns the names for a data structure.

Usage

anynames(data)

Details

Depending on the type of structure utilized in code, one needs to call either names or colnames to get information related to the data sets within the structure. The use of two separate functions can cause errors and slows development time as data structures passed from intermediate functions may change over time, resulting in a broken interface. By providing a thin layer over underlying accessors, this function attempts to expedite development and add a bit of polymorphism to the semantics of names. The explicit assumption is that data sets in two dimensional structures are organized by column, as this is compatible with time-series objects such as zoo and xts.

Examples

Run this code
m <- matrix(c(1,2,3,4,5,6), ncol=2)
anynames(m) <- c('d','e')
anynames(m)

v <- c(a=1,b=2,c=3,d=4,e=5)
anynames(v)

l <- list(a=1,b=2,c=3,d=4,e=5)
anynames(l)

df <- data.frame(a=1:10, b=1:10,c=1:10,d=1:10,e=1:10)
anynames(df)

Run the code above in your browser using DataLab