R/loadmatrix.R

"loadmatrix" <-
structure(function(filename){
  if(is.character(filename)) {file<-file(description=filename,open="r")
  }else file<-filename
  nn<-c("%")
  while(substr(nn[1],1,1)=="%") {
      nn<-read.table(file=file,nrows=1)
      print(paste(nn,collapse=" "))}

if (length(nn) == 2)
  { xx<-read.table(file=file,nrows=nn[[2]],fill=TRUE)
    n<-read.table(file=file,skip=1,nrows=nn[[2]])
    n<-as.matrix(n)
    rownames(n)<-xx[[2]]
    colnames(n)<-xx[[2]] }
 else
   {xxrow<-read.table(file=file,nrows=nn[[3]],fill=TRUE)
    xxcol<-read.table(file=file,nrows=nn[[2]]-nn[[3]],fill=TRUE)
    n<-read.table(file=file,skip=1,nrows=nn[[3]])
    n<-as.matrix(n)
    rownames(n)<-xxrow[[2]]
    colnames(n)<-xxcol[[2]] }
  as.matrix(n)
  }
, comment = "Load matrix from file that was produced by Pajek")

Try the blockmodelingTest package in your browser

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

blockmodelingTest documentation built on May 2, 2019, 5:57 p.m.