Given a variable isolated from a data frame, how do I get its name? It should work in functions where indexing is done internally (e.g. applied).
df<-data.frame(a=1:10,b=1:10)
names(df[,1])
gives:
>NULL
test<-df[,1]
test[0]
Here is an example where this might be useful:
library(plyr)
relabel<-colwise(function(column){
column<-paste(names(column),column)})
relabel(df)
gives
data.frame(a=c(.1,.2,.3,...), b=c(.1,.2,...))
Desired Results:
data.frame(a=c('a.1','a.2','a.3'), b=c('b.1','b.2', 'b.2'))
source
share