[R] Table of basic descriptive statistics like SPSS
John Kane
jrkrideau at yahoo.ca
Tue Mar 18 14:40:46 CET 2008
I don't think the OP was using Hmisc::describe. I
think it was psych::describe.
--- Frank E Harrell Jr <f.harrell at vanderbilt.edu>
wrote:
> John Kane wrote:
> > #How Can I create a text file with the output of
> > "describe"?
>
> sink('my.txt')
> describe( )
> sink()
>
> If you use LaTeX you'll get more (and better) output
> including tiny
> high-resolution histograms of continuous variables.
>
> Frank
>
> >
> > ?sink
> > ?write.table
> > ?write.csv
> >
> > #delete some variables.
> >
> > ?Extract
> > df[,-(10:12)]
> > df[, 1:9]
> >
> >
> > --- ukoenig at med.uni-marburg.de wrote:
> >
> >> Dear list readers,
> >> I want to:
> >>
> >> 1. Get a table of basic descriptive statistics
> for
> >> my variables
> >> with the variable names one below the other
> >> like SPSS descriptive statistics:
> >>
> >> Varname N Min Max Mean SD
> >> xxxx x x x x x
> >> xxx x x x x x
> >> ....
> >>
> >> 2. Delete some variables from a data frame or
> >> exclude variables
> >> from beeing analyzed.
> >>
> >> 3. Create a text file / redirect the terminal
> output
> >> to a
> >> file (it is supposed to be easy, but I could not
> >> find a solution)?
> >>
> >> 4. Create a latex/dvi file
> >>
> >> 5. Create a PDF file (can that be done within R?)
> >>
> >> This code took me some ours (I am new to R). What
> do
> >> you think about
> >> my solution? Are there easier ones? Comments
> >> welcome! Sorry if
> >> my questions look very basic and I hope they are
> >> understandable.
> >>
> >>
> >> #here is my code
> >> setwd("c:\\temp") #set working directory
> >>
> >> library(psych)
> >> library(xtable)
> >> library(tools)
> >>
> >> #Create example data frame with many variables
> >> df <- as.data.frame(matrix( rnorm(1000),
> ncol=100))
> >>
> >> df <- describe(df) #describe from lib psych
> >>
> >> #How Can I create a text file with the output of
> >> "describe"?
> >> #The "save as" function from the GUI saves
> >> #only last part of the output to a text file (the
> >> first part is cut)
> >>
> >>
> >> #delete some variables. Or can I exclude
> variables
> >> from
> >> #beeing analyzed by "describe" to reduce the
> numer
> >> of cols?
> >> df$kurtosis <- df$skew <- df$se <- NULL
> >>
> >> x.df <- xtable(df) #Create an xtable object
> >> print(x.df, tabular.environment = "longtable", ,
> >> floating = FALSE,
> >> file="c:\\temp\\descript.tex") #create
> latex
> >> file
> >>
> >> # produce dvi file in working directory (from
> tools)
> >> texi2dvi("c:\\temp\\descript.tex") #the lines
> below
> >> have to be added
> >>
> >> #Problem: these lines have to be added "manually"
> to
> >> the latex
> >> #before calling "texi2dvi":
> >>
> >> #\documentclass{article}
> >> #\usepackage{longtable}
> >> # Latex code
> >> #\end{document
> >>
> >>
> >> #Can I prodcuce a PDF file within R?
> >>
> >>
> >> Thanks a lot in advance!
> >> Udo
> >>
> >> ______________________________________________
> >> R-help at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained,
> >> reproducible code.
> >>
> >
> >
> >
> > [[elided Yahoo spam]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> >
>
>
> --
> Frank E Harrell Jr Professor and Chair
> School of Medicine
> Department of Biostatistics
> Vanderbilt University
>
Looking for the perfect gift? Give the gift of Flickr!
More information about the R-help
mailing list