"readallf"<- function(fn, prefix = "") { # use "File Save AS" to download this ascii file (" readin.txt") # use "File Save AS" to download DATA BASE as ascii file "ALL.txt" # run Splus and # > source("readin.txt") # > ls() and you should see this function # readallf - read in dataset(s) in 14 X 4 ascii format w/ Ids # Returns an S+ matrix where a row represents a patients # data #Input # fn - ascii file name # prefix - directory where ascii file stored # # Example: # readallf("ALL.txt","/usr2/users/home/datasets/") # (note - S+ matrices "bedata" & "nedata" automatically generated # no need for assignment operator "<-" ) #create list for "what" arguement to scan function # whatarg <- vector("list", 57) # create NULL list of length 57 whatarg[1] <- "" #assign first value character data (IDs) whatarg[2:57] <- 0 # assign remaining values numeric data # #read in file, stored as list # filename <- paste(prefix, fn, sep = "") list.x <- scan(file = filename, what = whatarg, multi.line = T) # # #unlist the numeric data & convert to matrix, use first element #of list (patient ids) as rownames # mat.x <- matrix(unlist(list.x[2:57]), ncol = 56) dimnames(mat.x) <- list(list.x[[1]], c("C.1.5", "C.2.5", "C.3.5", "C.4.5", "C.5.5", "C.6.5", "C.7.5", "C.8.5", "C.9.5", "C.10.5", "C.11.5", "C.12.5", "BE1.1.5", "BE1.2.5", "BE1.3.5", "BE1.4.5", "BE10.1.5", "BE10.2.5", "BE10.3.5", "BE10.4.5", "BE100.1.5", "BE100.2.5", "BE100.3.5", "BE100.4.5", "C.1.7", "C.2.7", "C.3.7", "C.4.7", "C.5.7", "C.6.7", "C.7.7", "C.8.7", "C.9.7", "C.10.7", "C.11.7", "C.12.7", "BE1.1.7", "BE1.2.7", "BE1.3.7", "BE1.4.7", "BE10.1.7", "BE10.2.7", "BE10.3.7", "BE10.4.7", "BE100.1.7", "BE100.2.7", "BE100.3.7", "BE100.4.7", "PHA.1", "PHA.2", "PHA.3", "PHA.4", "CAND.1", "CAND.2", "CAND.3", "CAND.4")) # # # now break apart bedata & nedata based on "AC" & "OR" values in row labels # rowlabel.list <- dimnames(mat.x)[1] # get row labels rowlabel.vec <- unlist(rowlabel.list) # coerece to vector rowlabel.sub <- substring(rowlabel.vec, 1, 2) # first 2 characters # # assign matrices # assign("bedata", mat.x[rowlabel.sub == "AC", ], w = 1) assign("nedata", mat.x[rowlabel.sub == "OR", ], w = 1) } #