R/design.mat.R

Defines functions design.mat

Documented in design.mat

design.mat<-function(book, locations) {
  n<-nrow(book)
  m<-length(locations)
  X<-matrix(1,c(n,1))
  colnames(X)<-"constant"
  for(j in 1:length(locations)){
    beta<-book[,locations[j]]
    beta<-as.factor(beta)
    nivel<-  levels(beta)
    P<-as.character(beta)
    for(i in 1:n){
      xadd<-c(as.numeric(nivel%in%P[i]))
      if(i==1)Y<-xadd
      if(i> 1)Y<-rbind(Y,xadd)
    }
    colnames(Y)<-nivel
    X<-cbind(X,Y)
  }
  rownames(X)<-1:n
  return(X)
}

Try the agricolae package in your browser

Any scripts or data that you put into this service are public.

agricolae documentation built on Oct. 23, 2023, 1:06 a.m.