Export summary info AND structure of data frame to csv file

I have a dataframe in R (aa) that I imported to R from a SAS export file. It has over 350 variables. I want to export summary information about the variables to a csv file and have used this:

varsum = summary(aa)
write.csv(varsum, file = 'varsum.csv')

This gives me the variable name and min, max, NA's etc but I also want to include:

  1. variable type (int, num etc)
  2. variable label (an extended explanation of the variable that comes across with the XPT file. I can see this label when I used View under the variable name.

I couldn't help but notice that you recently posted a very similar question on community.rstudio.com and on a different website.

The current way you've done this is generally considered not-OK

From: FAQ: Is it OK if I cross-post?

Was not sure if the was allowed or not. Will not do again. In any case the proposed solution to this was

varsum <- sapply(a, function(x) c(summary(x), type = class(x), label = ...))
write.csv(varsum, file = 'varsum.csv')

But this did not work. and so I did a messy two step work around to tabulate all the variables and basic information and lables.

varsum = summary(aa) 
write.csv(varsum, file = 'varsum.csv') 
varlab = get_label(aa, def.value = NULL, case = NULL) 
write.csv(varlab, file = 'varlab.csv')

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.