0

I run my script one time for example and firstly I obtain one matrix mat_temp based on randomization functions as follows:

Time Measurement
22:35:00 0
22:40:00 0
22:45:00 0
22:50:00 0
22:55:00 0
23:00:00 0
23:05:00 0
23:10:00 0.11
23:15:00 0.28
23:20:00 0
23:25:00 0.22
23:30:00 0.08
23:35:00 0.08
23:40:00 0
23:45:00 0.11
23:50:00 0.06
23:55:00 0.23

and then I get the results for

(1). sum = 1.17
(2). n_wet = 8 (measurement > 0)
(3). n_dry = 9 (measurement == 0)
(4). intensity = 0.15

The data in mat_temp and the corresponding results change every time if I run the script. And I want to run it for 100 times and average the results. I found the possible solution like:

 lapply(1:100,function(n)source("my_script.R"))

I tested it with two times and it gave results as follows, where the two values: 2.128558 and 2.160195 are only the results for intensity. There was not results for the others: sum, n_wet and n_dry

 > lapply(1:2,function(n)source("my_script.R"))
[[1]]
[[1]]$value
[1] 2.128558

[[1]]$visible
[1] FALSE


[[2]]
[[2]]$value
[1] 2.160195

[[2]]$visible
[1] FALSE

Can you explain why it only gives one result and how can I manage to average the results after I run my script for 100 times?

Ding
  • 7
  • 3
  • 1
    Hello R user, You need to provide a minimal reproducible example so that we can help you. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for how to do this – hackR Oct 14 '17 at 23:10
  • 1
    We'll need to know the contents of "my_script.R" in order to help you with this – shrgm Oct 14 '17 at 23:24
  • Hello, thank you for the replies but my script has hundreds of lines and it can only be run based on one .txt file. I am very new in R and I am not sure I can provide my script here with the .txt file. I just need to run the whole script for 100 times and average the four final results as I explained in the question. It would be very helpful if you can give some possible solutions and I can try in my script. Thank you again! – Ding Oct 15 '17 at 10:07

0 Answers0