This might sound trivial, but I am facing an issue in finding column name of a dataframe(with 1 column)
> a <- data.frame(x = c(1,2,3,4,5), y = c("a", "a","c","d","r")) > a x y 1 1 a 2 2 a 3 3 c 4 4 d 5 5 r > colnames(a) [1] "x" "y" > names(a) [1] "x" "y" > a1 <- a[,1] > class(a1) [1] "numeric" > a1 [1] 1 2 3 4 5 > a1 <- as.data.frame(a[,1]) > a1 a[, 1] 1 1 2 2 3 3 4 4 5 5 > colnames(a1) [1] "a[, 1]" > names(a1) [1] "a[, 1]" > I am selecting 1 column from the dataframe "a", I want the output to be "x" when I query for the column name of a1. Appreciate help on this. Thanks
dropargument:a1 <- a[,1,drop=FALSE]