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:
- variable type (int, num etc)
- 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')