Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Store all column names and its index pairs as a dataframe/dictionary

I tried to get column names and its index, and save the result as a dataframe or dictionary:

df <- data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10))

How could I do that? Thanks.

column index
a   1
b   2
c   3

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

data.frame(column = colnames(df), index = seq_along(df))
#   column index
# 1      a     1
# 2      b     2
# 3      c     3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading