我试图想办法在for循环之外运行这个脚本。我尝试过按功能,但这对我没用。理想情况下,它可以在基地R内完成。任何建议将不胜感激。
这段代码的作用是...... 1.创建df planTable 2. planTable从下表的前三行开始。 3.从stage = 1到numOfStages = 20迭代 4.跳转到stage = 1的for循环,并跟随if(stage == 1)语句 跳出那个ifelse并遵循整个代码 6.完成for循环后,最终结果就是下面的表格。
TIME STAGE WELL_NM
1 0.0000 0 2. PLAN
2 0.7000 0 2. PLAN
3 0.7000 1 2. PLAN
MIRU <- 0.7
numofStages <- 20
fG <- 4
GR <- .000034
nptPer <- .0030
STIM <- .0001
TIME <- c(0, MIRU, MIRU)
STAGE <- c(0, 0, 1)
WELL_NM <- c("2. PLAN", "2. PLAN", "2. PLAN")
planTable <- data.frame(TIME, STAGE, WELL_NM)
Row <- 4
for (stage in 1:numOfStages)
{
if (stage == 1) {
planTable[Row, 1] <- planTable[Row - 1, 1] + nptPer
planTable[Row, 2] <- stage
planTable[Row, 3] <- "2. PLAN"
Row=Row + 1
} else {
if (stage == 2) {
perf <-(KOP / vtRIH)
}
else {
perf <-KOP * (1 / vtRIH + 1 / vtPOOH)
}
planTable[Row, 1] = planTable[Row - 1, 1] + .5* nptPer
planTable[Row, 2] = stage
planTable[Row, 3] = "2. PLAN"
Row=Row + 1
if(stage %% fG==0){
mantc<-GR
}
else{
mantc<-0
}
planTable[Row, 1] = planTable[Row - 1, 1] + STIM
planTable[Row, 2] = stage
planTable[Row, 3] = "2. PLAN"
Row=Row + 1
}
}
输出是数据帧......
TIME STAGE WELL_NM
1 0.000 0 2. PLAN
2 0.026 0 2. PLAN
3 0.026 1 2. PLAN
4 0.028 1 2. PLAN
5 0.030 2 2. PLAN
6 0.031 2 2. PLAN
7 0.033 3 2. PLAN
8 0.034 3 2. PLAN
9 0.036 4 2. PLAN
10 0.037 4 2. PLAN
11 0.039 5 2. PLAN
12 0.040 5 2. PLAN
13 0.041 6 2. PLAN
14 0.043 6 2. PLAN
15 0.044 7 2. PLAN
16 0.046 7 2. PLAN
17 0.047 8 2. PLAN
18 0.049 8 2. PLAN
19 0.050 9 2. PLAN
20 0.052 9 2. PLAN
21 0.053 10 2. PLAN
22 0.054 10 2. PLAN
23 0.056 11 2. PLAN
24 0.057 11 2. PLAN
25 0.059 12 2. PLAN
26 0.060 12 2. PLAN
27 0.062 13 2. PLAN
28 0.063 13 2. PLAN
29 0.064 14 2. PLAN
30 0.066 14 2. PLAN
31 0.067 15 2. PLAN
32 0.069 15 2. PLAN
33 0.070 16 2. PLAN
34 0.072 16 2. PLAN
35 0.073 17 2. PLAN
36 0.075 17 2. PLAN
37 0.076 18 2. PLAN
38 0.077 18 2. PLAN
39 0.079 19 2. PLAN
40 0.080 19 2. PLAN
41 0.082 20 2. PLAN
42 0.083 20 2. PLAN
43 0.085 21 2. PLAN
44 0.086 21 2. PLAN
45 0.087 22 2. PLAN
46 0.089 22 2. PLAN
47 0.090 23 2. PLAN
48 0.092 23 2. PLAN