| 1 |
\name{to.data.frame} |
| 2 |
\alias{to.data.frame} |
| 3 |
\title{Convert an Array into a Data Frame} |
| 4 |
\description{ |
| 5 |
\code{to.data.frame} converts an array into a data frame, in such a way |
| 6 |
that a chosen dimensional extent forms variables in the data frame. |
| 7 |
The elements of the array must be either atomic, data frames |
| 8 |
with matching variables, or coercable into such data frames. |
| 9 |
} |
| 10 |
\usage{ |
| 11 |
to.data.frame(X,as.vars=1,name="Freq") |
| 12 |
} |
| 13 |
\arguments{ |
| 14 |
\item{X}{an array.} |
| 15 |
\item{as.vars}{a numeric value or a character string. |
| 16 |
If it is a numeric value then it indicates the dimensional extend |
| 17 |
which defines the variables. If it is a character string then it is |
| 18 |
matched against the names of the dimenstional extents. This is |
| 19 |
applicable e.g. if \code{X} is a contingency table and the |
| 20 |
dimensional extents are named after the cross-classified factors. |
| 21 |
Takes effect only if \code{X} is |
| 22 |
an atomic array. If \code{as.vars} equals zero, a new variable |
| 23 |
is created that contains the values of the array, that is, |
| 24 |
\code{to.data.frame} acts on the array \code{X} |
| 25 |
like \code{as.data.frame(as.table(X))} |
| 26 |
} |
| 27 |
\item{name}{a character string; the name of the variable |
| 28 |
created if \code{X} is an atomic array and \code{as.vars} equals zero. |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
\value{ |
| 33 |
A data frame. |
| 34 |
} |
| 35 |
|
| 36 |
\examples{ |
| 37 |
berkeley <- Aggregate(Table(Admit,Freq)~.,data=UCBAdmissions) |
| 38 |
berktest1 <- By(~Dept+Gender, |
| 39 |
glm(cbind(Admitted,Rejected)~1,family="binomial"), |
| 40 |
data=berkeley) |
| 41 |
berktest2 <- By(~Dept, |
| 42 |
glm(cbind(Admitted,Rejected)~Gender,family="binomial"), |
| 43 |
data=berkeley) |
| 44 |
Stest1 <- Lapply(berktest2,function(x)predict(x,,se.fit=TRUE)[c("fit","se.fit")]) |
| 45 |
Stest2 <- Sapply(berktest2,function(x)coef(summary(x))) |
| 46 |
Stest2.1 <- Lapply(berktest1,function(x)predict(x,,se.fit=TRUE)[c("fit","se.fit")]) |
| 47 |
to.data.frame(Stest1) |
| 48 |
to.data.frame(Stest2,as.vars=2) |
| 49 |
to.data.frame(Stest2.1) |
| 50 |
# Recasting a contingency table |
| 51 |
to.data.frame(UCBAdmissions,as.vars="Admit") |
| 52 |
} |
| 53 |
\keyword{manip} |