Hi everyone (Pardon the incorrect terminology of my previous post: "vertical
line...).

I have created a function that uses xtable to print table of frequencies and
percentages with a heading and some sample information  (the sample size and
missing values). The function and example data is below.

I want a horisontal line that separates the results from the  sample
information i.e. a horisontal line on the bottom of the line second from
last

example=data.frame(sample(c("A","B"),100,replace=TRUE))

label(example)="example"


freq.table.v<-function(x){

y=as.data.frame(rbind(table(x, dnn=label(x)),100*as.table(table(x))/sum(
as.table(table(x))) ), row.names=c("Frequency","Percent"))

y[,1]=sprintf("%.0f",y[,1])

f=as.data.frame(cbind(paste(": n=",length(x[,1])-sum(is.na(x)),sep=""),paste
("Missing=",sum(is.na(x)),sep="")))

Sample.info=t(f)

y=cbind(y,Sample.info)

#z=t(as.matrix(y))

a=xtable(t(as.matrix(y)), caption=paste("Table of\ ",label(x),sep=""),label=
label(x),align=c("l","r","r"))

print(a, file="",caption.placement="top", caption.lot=paste(label(x)))

invisible(a)

}

 freq.table.v(example)


In other words: At the moment I get


% latex table generated in R 2.8.0 by xtable 1.5-4 package % Wed Jun 17
08:53:44 2009 \begin{table}[ht] \begin{center} \caption{Table of example}
\label{example} \begin{tabular}{lrr} \hline & Frequency & Percent \\ \hline
A & 31 & 46 \\ B & 36 & 54 \\ Sample.info & : n=67 & Missing=33 \\ \hline
\end{tabular} \end{center} \end{table}


what I want is:


% latex table generated in R 2.8.0 by xtable 1.5-4 package % Wed Jun 17
08:53:44 2009 \begin{table}[ht] \begin{center} \caption{Table of example}
\label{example} \begin{tabular}{lrr} \hline & Frequency & Percent \\ \hline
A & 31 & 46 \\ B & 36 & 54 \\

\hline Sample.info & : n=67 & Missing=33 \\ \hline \end{tabular}
\end{center}

\end{table}


Second question: Ideally one wants a name that may include a space where the
variable name Sample.info is now. Something like "sample information". Two
sub-questions: 1. How does one print a label and not the variable name or
factor level. 2 What would be a technically correct name for this kind of
information (sample size and missing values)?


Thanks in advance


Chistiaan

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to