Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- read.round.lines <- function(path, n, type) {
- con <- file(paste(path,paste(n,type,sep="."),sep="/"),"r") # make the path
- lin <- readLines(con) # read line by line
- close(con)
- lin[lin != ""] # remove empty lines
- }
- read.round.df <- function(path, n, type) {
- lin <- read.round.lines(path, n, type) # read file line by line
- func <- function(str) strsplit(str, " ") # anonymous func for splitting
- getname <- function(list) list[[1]][1] # get name of var
- indnum <- if(type == "inp" && n != 0) 3 else 2 # workaround: inputs 1,2,... have odd data.
- getnum <- function(list) list[[1]][indnum] # get value of var
- linsplit <- lapply(lin,func) # get all split lines
- names <- lapply(linsplit,getname) # use linsplit to get names
- nums <- lapply(linsplit,getnum) # use linsplit to get numbers
- df <- data.frame(nums, row.names = n) # make a data frame
- names(df) <- names # set names
- df
- }
- read.rounds.df <- function(path, ns, type) {
- df <- data.frame() # init an empty data rame
- for(i in ns) { # go thru all rounds
- dfi <- read.round.df(path, i, type) # load specific round
- df <- rbind(df,dfi) # add new observation
- }
- df # and return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement