nams | R Documentation |
Return the column names of a dataframe or a matrix.
nams(x)
nams(x) <- value
x |
The matrix or data.frame to set the column names for. |
value |
The names to be given. |
Simply to have a single function for returning the column names, instead of
colnames()
for a matrix
and names()
for a data.frame
).
# Generate a matrix
X <- matrix(1, nrow=2, ncol=3)
colnames(X) <- c("c1","c2","c3")
D <- as.data.frame(X)
# Annoyingly this fails (for a matrix)
## Not run: names(X)
# Could use this everywhere
colnames(D)
# but this is shorter
nams(X)
nams(D)
# Also for assignment
nams(D) <- c("x1","x2","x3")
nams(D)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.