0

I wrote a code in R which has 2 variables in it: rep & x the code is written in a way that I should go inside the script to change the values for X and rep variables depends on the input data. I am wondering how can I automate this instead of going inside the script:

rm(list=ls())  
ls()           

data<-read.table(file="data.txt", header=T) 
colnames(data)  

rep<-1000 

x <- 88

diff_debv<-matrix(,nr=rep,nc=1)   
for (i in 1:rep) {        
  
  
  N<-nrow(data)    
  m1<-runif(1)    
  
  m2<-runif(1)     
  sd1<-runif(1)   
  sd2<-runif(1)   
  
  
  x1<-rnorm(N,m1,sd1)  
  x2<-rnorm(N,m2,sd2) 
  data0<-cbind(data,x1,x2)  
  data1<-data0[with(data0,order(-x1)),]  
  top40_x1 <-data1[1:x,]              
  dEBV2019_1 <- mean(top40_x1$run.15564)  
  data2<-data0[with(data0,order(-x2)),] 
   
  top40_x2<-data2[1:x,]                
   
  dEBV2019_2 <- mean(top40_x2$run.15564) 
  
  diff_debv[i,1]<-(dEBV2019_1-dEBV2019_2)
   
}

sd.diff_debv <- sd(diff_debv)

sd.diff_debv

data3<-data0[with(data0,order(-GEBV2017)),] 
data4<-data0[with(data0,order(-EBV2017)),]

top40_GEBV2017<- data3[1:x,]
top40_EBV2017<-data4[1:x,]
mean_top40_GEBV2017 <- mean(top40_GEBV2017$GEBV2017)
mean_top40_EBV2017 <- mean(top40_EBV2017$EBV2017)
diff_rank<-(mean_top40_GEBV2017-mean_top40_EBV2017)
type1_debv <- 1-(pnorm(diff_rank, 0, sd.diff_debv))
diff_rank 
sd.diff_debv 
type1_debv 

I want instead of going inside the script each time to change the values of x and rep, when I run the script in linux, 2 questions appear, and after answering to those question the script executes accordingly. for example:

R < script.r > result
what is the value for rep?
1000
what is the value for x?
88

Is there any function in R to such a work? any help or guidance will be appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.