colnames gives me the column names for a whole dataframe. Is there any way to get the name of one specified column. i would need this for naming labels when plotting data in ggplot.
So say my data is like this:
df1 <- data.frame(a=sample(1:50,10), b=sample(1:50,10), c=sample(1:50,10))
I would need something like paste(colnames(df1[,1])) which obviously won’t work.
any ideas?
you call the name like this:
however by removing your comma e.g.:
you can also call the names, becauseusing only
[x]not[,x]or[[x]]keeps the data.frame structure not reducing to a vector unlike$xand[,x]