Get column index from label in a data frame

前端 未结 7 992
忘掉有多难
忘掉有多难 2020-12-04 05:49

Say we have the following data frame:

> df
  A B C
1 1 2 3
2 4 5 6
3 7 8 9

We can select column \'B\' from its index:

&g         


        
7条回答
  •  孤街浪徒
    2020-12-04 06:29

    Following on from chimeric's answer above:

    To get ALL the column indices in the df, so i used:

    which(!names(df)%in%c()) 
    

    or store in a list:

    indexLst<-which(!names(df)%in%c())
    

提交回复
热议问题