0

I am new to r and work on boolean modelling - my nested loop gives output of 50 values of rtk in terms of 0 and 1, how to store this output in a dataframe , cbind is not working . Please help. 2. Also I would like to introduce a time loop ie if j = is 5 seconds I want rtk to change accoding to nwki value in i0 for j =1to 3 and for time j = 4,5 seconds i want rtk to change accoding to nwk value in i0

CODE IS AS FOLLOWS

library (BoolNet)#make sure lib is installed
library(igraph)
setwd("C:/Users/neha gopal/Desktop/IISC-mkj/r for boolean")#"

nwki<- loadNetwork("rtkufi.txt",bodySeparator =",",lowercaseGenes = FALSE)#"
nwk<- loadNetwork("rtkuf.txt",bodySeparator =",",lowercaseGenes = FALSE)#"
inc<-c(1,0,0,0,0,0,0,0,0,0)#vector
stF<- stateTransition(network=nwki,state= inc,type = "asynchronous")
stF
#loops working
rtk_values <-rep(0,50)# empty vector for total no of rtk  output values 
rtk_values
ts<- 10
for (i in 1:ts)# trajectories i=10
{
  i0 <- inc
  rtk_values <-rep(0,50)
  rtk <- i0[2]


tr<-5 #time j=5


for (j in 1:tr)
{


  i0 <- stateTransition(network=nwki,state= i0,type = "asynchronous")
  rtk <- i0[2]
  print (paste0( ",Im in J and my j is ", j, " and my i is", i,"rtk is" , rtk ))

}

}

#table  NOT working


rtk_values[j]= rtk
rtk_table <- cbind.data.frame( rtk_values, rtk)
  • 1
    Please make your example reproducible and minimal (e.g. using the bare minimum of functions/packages which demonstrates your problem). Form where I'm sitting, it would also help if you format/indent your code. – Roman Luštrik Feb 15 '20 at 08:46

1 Answers1

1

The best way to ask a question is to provide a reproducible example. If your question is how to store variables from a for loop, this would be a way of doing it:

result <- list() # initalize an empty list

for (i in 1:10){
  result[[i]] <- i # populate list with every loop
}

The same system can be used for nested loops:

result <- list()
for (i in 1:10){
  result_nested <- list() # initialize an empty list within the loop
  for (nested in 1:5){
    result_nested[[nested]] <- nested # populate the results from the nested loop. 
  }
  result[[i]] <- result_nested # populate the result from the nested loop to the parent loop
}
MKR
  • 1,620
  • 7
  • 20