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
Table of basic descriptive statistics like SPSS
11 messages · ukoenig at med.uni-marburg.de, Martin Henry H. Stevens, Liviu Andronic +5 more
Hi Udo, See the Hmisc and Design libraries by Frank Harrell, and some associated PDF docs by Alzola and Harrell describing data management and display. Hank
On Mar 17, 2008, at 2:05 PM, 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.
Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ "If the stars should appear one night in a thousand years, how would men believe and adore." -Ralph Waldo Emerson, writer and philosopher (1803-1882)
#How Can I create a text file with the output of "describe"? ?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]]
On Mon, Mar 17, 2008 at 7:05 PM, <ukoenig at med.uni-marburg.de> wrote:
1. Get a table of basic descriptive statistics for my variables with the variable names one below the other like SPSS descriptive statistics:
[trimmed]
2. Delete some variables from a data frame or exclude variables from beeing analyzed.
Rcmdr can help you perform these; hence you could learn a correct syntax.
4. Create a latex/dvi file
There is also xtable() that can export objects to LaTeX. Soon this will be possible graphically from Rcmdr, too. Hope this is of help, Liviu
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
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 ....
This looks very much like the output of the "describe" function in the prettyR package. You can specify which summary stats you want (even roll your own).
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)?
sink("myoutputfile.txt")
do.your.stuff(...)
sink()
OR
maybe you would enjoy "htmlize" or "R2html" in the prettyR package.
4. Create a latex/dvi file
You do this with Sweave, I think.
5. Create a PDF file (can that be done within R?)
For plots, the pdf device. Jim
Jim Lemon wrote:
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 ....
This looks very much like the output of the "describe" function in the prettyR package. You can specify which summary stats you want (even roll your own).
And if that's not enough: library(pastecs) data(trees) t(stat.desc(trees)) ?stat.desc
2. Delete some variables from a data frame or exclude variables from beeing analyzed.
df2 <- df[ , -c(1, 3), drop = FALSE] for instance to eliminate variables in columns 1 and 3, but there are many other ways to select variables to use in an analysis, beginning with the formula interface, see, e.g., ?lm.
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)?
sink("myoutputfile.txt")
do.your.stuff(...)
sink()
OR
maybe you would enjoy "htmlize" or "R2html" in the prettyR package.
... or the R2html package!
4. Create a latex/dvi file
You do this with Sweave, I think.
See also functions in the Hmisc package.
5. Create a PDF file (can that be done within R?)
For plots, the pdf device.
See ?pdf
Please, note first search commands:
apropos("pdf")
RSiteSearch("latex")
Using these, you would have found by yourself the various corresponding
functions.
Philippe
Jim
______________________________________________ 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.
At 7:05 PM +0100 3/17/08, 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 ....
Udo, To limit the number of columns of describe, set skew=FALSE to delete variables from the description, do so in the call to describe e.g., df <- as.data.frame(matrix( rnorm(1000), ncol=100)) describe(df[c(1:10,20:30)],skew=FALSE) describe(df[-c(10:98)],range=FALSE,skew=FALSE) to print the output into LaTeX, look at the the Sweave package. Bill
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.
William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for statistics: http://personality-project.org/r
William Revelle wrote:
At 7:05 PM +0100 3/17/08, 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 ....
Udo, To limit the number of columns of describe, set skew=FALSE
The describe function in the Hmisc package does not have a skew option. Please list the relevant package when talking about describe. Thanks Frank
to delete variables from the description, do so in the call to describe e.g., df <- as.data.frame(matrix( rnorm(1000), ncol=100)) describe(df[c(1:10,20:30)],skew=FALSE) describe(df[-c(10:98)],range=FALSE,skew=FALSE) to print the output into LaTeX, look at the the Sweave package. Bill
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.
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
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!
Dear all, thank you very much for the provided support and all the hints, which were very helpful! Now I know how to continue.
See ?pdf
Please, note first search commands:
apropos("pdf")
RSiteSearch("latex")
Using these, you would have found by yourself the various corresponding
functions.
Philippe Sorry Philippe, I always try to solve problems myself before contacting the list, but sometimes you get so many results, that it?s somewhat confusing for an R-novice like me. I will use apropos() and RsiteSearch() next time, thank you very much..
I don't think the OP was using Hmisc::describe. I think it was psych::describe.
Yes, it was describe from lib psych. Regards, Udo Quoting John Kane <jrkrideau at yahoo.ca>:
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!
http://www.flickr.com/gift/