# 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)
if (FALSE) 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)
Run the code above in your browser using DataLab