freqc {lazy.tools}R Documentation

Frequency Distribution of Many Discrete Variables

Description

Frequency Distribution of Many Discrete Variables

Usage

freqc(..., useNA = "no", sortrow = 1, sortcol = 0, debug = 0)

Arguments

...

Discrete/categorical variables to be tabulated

useNA

= "ifany" if the frequency of NA is needed.

sortrow

= 0 not to sort the rows of the result (category values)

sortcol

= 1 to sort the column of the result (variable names)

debug

= 1 to print intermediate result

Details

If X is a matrix consisting of discrete variables,
freqc(X) is equivaleet to

  freq=lapply(as.list(X),table)
  res2=mapply( function(x,name){
    y=matrix(x,1); colnames(y)=names(x); rownames(y)=name;
    return(as.data.frame(y))  }
    ,  freq, names(freq) )

Space or Blank values will be denoted as V1.

Value

A values x variables matrix containing the frequencies.
F <- freqc( a, b ) returns a matrix F whose i-j element contains the frequency of value rownames(F)[i] in the variable colnames(F)[j].

Examples

set.seed(1701)
a <- sample(1:9,20,replace=1)
b <- letters[sample(1:9,20,replace=1)]
c <- sample(3:5,20,replace=1)
d <- letters[sample(5:9,20,replace=1)]

a[9] <- NA
b[3:4] <- NA

data <- data.frame( a, b )

res1 <- freqc(a,b,c,d)
res2 <- freqc(data,c,d)
res3 <- freqc(c,d,a,b)
Print(res1,res2,res3)
res4 <- freqc(c,d,a,b, sortrow=0)
res5 <- freqc(c,d,a,b, sortcol=1)
Print(res1,res4,res5)

res11 <- freqc(a,b,c,d, useNA="ifany")
res21 <- freqc(data,c,d, useNA="ifany")
Print(res11,res21)


[Package lazy.tools version 0.1.6 ]