mw.enumerate {ldsa}R Documentation

~~function to do ... ~~

Description

~~ A concise (1-5 lines) description of what the function does. ~~

Usage

mw.enumerate(dat)

Arguments

dat ~~Describe dat here~~

Details

~~ If necessary, more details than the description above ~~

Value

~Describe the value returned If it is a LIST, use

comp1 Description of 'comp1'
comp2 Description of 'comp2'

...

Warning

....

Note

~~further notes~~

~Make other sections like Warning with section{Warning }{....} ~

Author(s)

~~who you are~~

References

~put references to the literature/web site here ~

See Also

~~objects to See Also as help, ~~~

Examples

##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--    or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function(dat){
  #Create functions to calculate binary values
  bv<-function(x)
    sum(2^(1:length(x)-1)*x)
  bn<-function(x,len){
    v<-rep(0,len)
    for(i in 1:len){
      v[i]<-x%%2
      x<-x%/%2
    }
    v
  }
  #Write a function to add values and freqs to y (and to eliminate duplicates)
  addvalfreq<-function(y){
    #Create a function to calculate binary values
    y<-cbind(y,apply(y,1,bv))  #Compute binary values for all sequences
    y<-y[order(y[,NCOL(y)]),]      #Sort rows into ascending order
    frq<-as.vector(table(y[,NCOL(y)]))    #Build a frequency vector
    y<-y[!duplicated(y[,NCOL(y)]),]       #Remove duplicates
    y<-cbind(y,frq)   #Append the frequencies (which are ordered by bv)
    y
  }
  #Tabulate the existing data
  nmb<-NCOL(dat)
  dat<-dat[!apply(is.na(dat),1,any),]
  dat<-addvalfreq(dat)
  #Construct the table of possibilities
  tab<-vector()
  for(i in 0:(2^nmb-1)){
    temp<-c(bn(i,nmb),0)
    temp2<-match(i,dat[,nmb+1])
    if(!is.na(temp2))
      temp[nmb+1]<-dat[temp2,nmb+2]
    tab<-rbind(tab,temp)
  }
  #Return the table
  tab
  }

[Package ldsa version 0.1-2 Index]