Reputation: 33
I have an R dataframe where the Column names also have the label attributes. I want to export this dataframe to excel. In the excel file, I would like to display the Column label as the header instead of the Column name.
I have tried some packages like openxlsx, but they seem to only have the option of using the Column names as the headers.
This is the variable name and label shown underneath. I would like to export this data frame to an excel file. In the excel file, I would like to have "Internal id for the study" as the header instead of the default "studyid"
Upvotes: 2
Views: 2470
Reputation: 683
Since you haven't provided an example it's hard to understand exactly what you mean, so bare with me if I have misunderstood.
From what I understand, you have a dataframe that has variables, and each variable has a label attribute. If you want to use these attributes instead of the variable names, then you can use the Hmisc
-package:
library(Hmisc)
names(df) <- Hmisc::label(df)
Now you have effectively replaced the variable names with the variable labels, and this should be what you see in excel after the export.
Let me know if this helps you.
Upvotes: 2