contract {memisc} | R Documentation |
contract()
contracts data into pattern-frequency format, similar
to a contatenation of table()
(or xtabs
) and
as.data.frame()
. Yet it uses much less memory if patterns
are sparse, because it does not create rows for patterns that do not occur.
contract(x,...) ## S3 method for class 'data.frame' contract(x,by=NULL, weights=NULL,name="Freq", force.name=FALSE,sort=FALSE,drop.na=TRUE,...) ## S3 method for class 'data.set' contract(x,by=NULL, weights=NULL,name="Freq", force.name=FALSE,sort=FALSE,drop.na=TRUE,...)
x |
an object of class |
by |
the formula or a vector of variable names (quoted or not quoted).
Specifies the patterns (and optionally weights).
If |
weights |
a numeric vector of weights or |
name |
a character string, the name of the variable that containts the frequency counts of the value patterns. |
force.name |
a logical value, defaults to |
sort |
a logical value, defaults to |
drop.na |
a logical value, defaults to |
... |
further arguments, passed to methods or ignored. |
If x
is a data fame, the value of contract()
is also a
data frame. If it is a "data.set"
object, the result is also a
"data.set"
object.
iris_ <- sample(iris,size=nrow(iris),replace=TRUE) w <- rep(1,nrow(iris_)) contract(iris[4:5]) contract(iris[4:5],sort=TRUE) contract(iris[4:5],weights=w,sort=TRUE) contract(iris,by=c(Petal.Width,Species),sort=TRUE) contract(iris,by=~Petal.Width+Species) contract(iris,by=w~Species) library(MASS) contract(housing, by=Sat~Infl+Type+Cont, weights=Freq) contract(housing, by=Sat~Infl+Type+Cont, weights=Freq, name="housing",force.name=TRUE )