Get column index from label in a data frame

前端 未结 7 978
忘掉有多难
忘掉有多难 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:50

    I wanted to see all the indices for the colnames because I needed to do a complicated column rearrangement, so I printed the colnames as a dataframe. The rownames are the indices.

    as.data.frame(colnames(df))
    
    1 A
    2 B
    3 C
    

提交回复
热议问题