[R] How to access data frame column name using variable ??

arun smartpink111 at yahoo.com
Tue Dec 3 21:10:06 CET 2013


Hi,
Try:
comb[,as.numeric(temp[1])]
#[1] "V1" "V2"
 comb[,as.numeric(temp[3])]
#[1] "V1" "V3"



A.K.


i have two data frame 

>comb 
         [,1]   [,2]    [,3]   [,4]   [,5]    [,6] 
[1,]    "V1"   "V1"   "V1"   "V1"   "V1"   "V1" 
[2,]    "V2"   "V2"   "V2"   "V3"   "V3"   "V4" 


>table 

    V1           V2 
1 V1V2          3 
2 V1V3          3 
5 V2V3          3 


i select row name by function 
rownames(table) and stored it in a data frame 

temp<-data.frame() 
temp<-rowname(table) 

i want to selcect column of other data frame using this reference. 

comb[,temp[1]]..but its not working.. 

because temp[1] is "1" 
comb[,"1"] 
is not vaild. 

who to over come this??



More information about the R-help mailing list