automation - Creating Automatin in R -


i have created script analyzes set of raw data , converts many different formats based on different parameters , functions. have 152 more raw data sheets go, have use script on each one. however, there times might decide need change variable or parameter , come parameter list @ top of spreadsheet affect rest of functions in large script.

  1. global variables aren't answer problem, best illustrated through example:

    exceedes <- function (l=null, r=null) {  if (is.null(l) | is.null(r))  { print ("mycols: invalid l,r.") return (null)                } options (na.rm = true) test <-(mean(l, na.rm=true)-r*sd(l,na.rm=true)) test1 <- ifelse(is.na(l), na, ifelse(l > test, 1, 0)) return (test1) }  l=rocc[,2] r=.08 rocc$newcolumn <- exceedes(l,r) names(rocc)[names(rocc)=="newcolumn"]="exceedes1"  l=rocc[,2] r=.16 rocc$newcolumn <- exceedes(l,r) names(rocc)[names(rocc)=="newcolumn"]="exceedes2"  l=rocc[,2] r=.24 rocc$newcolumn <- exceedes(l,r) names(rocc)[names(rocc)=="newcolumn"]="exceedes3" 

so in above example, have way @ top of script change range of r , have affect rest of script because function repeated 152 times. way can think of doing copy , paste function on , on different variable each time, , set globally. have imagine there simpler way, function possibly needs rearranged perhaps?

  1. file names , output names. not sure whether possible example input.csv's come in format 1 dataset titled 123 124, 125 etc. , have r know take next dataset, , output dataset specific folder on computer without me having type in read.csv(file="123.csv"), , write.csv(example, file="123.csv) , on?

  2. general formatting of automation script before dive automation, procedure going to copy , past script 152 times on , change filename , output name each one. sounds ridiculous, lack of programming skills not sure better way change it. ideas?

thanks in advance.

you can rerun function different parameters constructing vector of paremters (say r)

r <- c(seq(0.1, 1, = 0.01)) 

and run exceedes function length(r) times using sapply.

exceedes <- function(r, l) {} #notice argument order sapply(x = r, fun = exceedes, l = rocc[, 2]) 

you can pass other arguments function (e.g. file.name) , use create whatever file name need.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -