If conditions nested in for loop not executing
I've put together the following code snippet. It will run, without error, but the "StandPlotTree_ID_Past" variable is unchanged, in any row.
I'm not sure how the code is escaping the loop without any of the if loops executing. I've included a sampling of the input dataset. The full input dataset is substantial.
for (i in nrow(FVS_TreeInit)){
if (FVS_TreeInit[i,"Plot_ID"] == "R8"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R7T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R7"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R6T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R6"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R5T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R5"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R4T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R4"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R3T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R3"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R2T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R2"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R1T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else if (FVS_TreeInit[i,"Plot_ID"] == "R1"){
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- paste(FVS_TreeInit[i,"Stand_ID"],"R0T",FVS_TreeInit[i,"Tree_ID"],sep="")
} else{
FVS_TreeInit[i,"StandPlotTree_ID_Past"] <- NA
}
}
Sample dataset (csv):
Stand_ID,Plot_ID,StandPlot_ID,Tree_ID,Tree_Count,History,DBH,DG,Ht,HTG,HtTopK,CrRatio,Damage1,Severity1,Damage2,Severity2,Damage3,Severity3,TreeValue,Prescription,Slope,Aspect,PV_Code,TopoCode,SitePrep,Species,Age,StandPlotTree_ID,StandPlotTree_ID_Past
D18P186001,R0,D18P186001R0,1,,,4.76378225,,23.29396369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T1,
D18P186001,R0,D18P186001R0,2,,,1.259843219,,12.46719184,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T2,
D18P186001,R0,D18P186001R0,3,,,0.275590695,,5.249344078,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T3,
D18P186001,R0,D18P186001R0,4,,,0.629921609,,9.186351844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T4,
D18P186001,R0,D18P186001R0,5,,,0.1968505,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T5,
D18P186001,R0,D18P186001R0,6,,,3.70078925,,18.70078737,,,,,,,,,,,,,,,,,ABBA,26,D18P186001R0T6,
D18P186001,R0,D18P186001R0,7,,,2.834647125,,17.71653631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T7,
D18P186001,R0,D18P186001R0,8,,,1.259843219,,10.17060369,,,,,,,,,,,,,,,,,,,D18P186001R0T8,
D18P186001,R0,D18P186001R0,9,,,2.283465875,,16.07611631,,,,,,,,,,,,,,,,,,,D18P186001R0T9,
D18P186001,R0,D18P186001R0,10,,,1.181103,,14.76378,,,,,,,,,,,,,,,,,,,D18P186001R0T10,
D18P186001,R0,D18P186001R0,11,,,1.535433938,,15.09186369,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T11,
D18P186001,R0,D18P186001R0,12,,,4.212600625,,21.98162737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T12,
D18P186001,R0,D18P186001R0,13,,,3.30708825,,20.01312369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T13,
D18P186001,R0,D18P186001R0,14,,,1.259843219,,8.2021,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T14,
D18P186001,R0,D18P186001R0,15,,,4.212600625,,23.29396369,,,,,,,,,,,,,,,,,ABBA,28,D18P186001R0T15,
D18P186001,R0,D18P186001R0,16,,,3.149608,,18.04462,,,,,,,,,,,,,,,,,ABBA,28,D18P186001R0T16,
D18P186001,R0,D18P186001R0,17,,,1.181103,,8.530183687,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T17,
D18P186001,R0,D18P186001R0,18,,,0.944882438,,10.82677184,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T18,
D18P186001,R0,D18P186001R0,19,,,0.393701,,7.217848156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T19,
D18P186001,R0,D18P186001R0,20,,,0.314960805,,7.874016313,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T20,
D18P186001,R0,D18P186001R0,21,,,2.362206,,11.81102369,,,,,,,,,,,,,,,,,ABBA,22,D18P186001R0T21,
D18P186001,R0,D18P186001R0,22,,,0.314960805,,7.217848156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T22,
D18P186001,R0,D18P186001R0,23,,,1.062992719,,10.17060369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T23,
D18P186001,R0,D18P186001R0,24,,,3.93701,,18.37270369,,,,,,,,,,,,,,,,,ABBA,25,D18P186001R0T24,
D18P186001,R0,D18P186001R0,25,,,4.76378225,,19.02887263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T25,
D18P186001,R0,D18P186001R0,26,,,0.748031891,,8.2021,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T26,
D18P186001,R0,D18P186001R0,27,,,0.944882438,,7.545931844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T27,
D18P186001,R0,D18P186001R0,28,,,3.267718375,,19.35695631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T28,
D18P186001,R0,D18P186001R0,29,,,0.314960805,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T29,
D18P186001,R0,D18P186001R0,30,,,0.472441219,,9.186351844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T30,
D18P186001,R0,D18P186001R0,31,,,4.606301625,,20.34120737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T31,
D18P186001,R0,D18P186001R0,32,,,4.055120375,,20.34120737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T32,
D18P186001,R0,D18P186001R0,33,,,0.433071109,,8.2021,,,,,,,,,,,,,,,,,,,D18P186001R0T33,
D18P186001,R0,D18P186001R0,34,,,1.023622562,,9.186351844,,,,,,,,,,,,,,,,,,,D18P186001R0T34,
D18P186001,R0,D18P186001R0,35,,,0.5905515,,9.84252,,,,,,,,,,,,,,,,,,,D18P186001R0T35,
D18P186001,R0,D18P186001R0,36,,,0.748031891,,10.17060369,,,,,,,,,,,,,,,,,,,D18P186001R0T36,
D18P186001,R0,D18P186001R0,37,,,3.425198625,,17.71653631,,,,,,,,,,,,,,,,,ABBA,30,D18P186001R0T37,
D18P186001,R0,D18P186001R0,38,,,4.29134075,,22.30971263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T38,
D18P186001,R0,D18P186001R0,39,,,3.93701,,18.70078737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T39,
D18P186001,R0,D18P186001R0,40,,,4.251970875,,21.65354369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T40,
D18P186001,R0,D18P186001R0,41,,,4.09449025,,23.62204737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T41,
D18P186001,R0,D18P186001R0,42,,,6.181105625,,26.57480525,,,,,,,,,,,,,,,,,ABBA,24,D18P186001R0T42,
D18P186001,R0,D18P186001R0,43,,,3.858269875,,22.30971263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T43,
D18P186001,R0,D18P186001R0,44,,,3.7401595,,20.66929263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T44,
D18P186001,R0,D18P186001R0,45,,,0.5905515,,6.233595922,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T45,
D18P186001,R0,D18P186001R0,46,,,1.259843219,,12.13910816,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T46,
D18P186001,R0,D18P186001R0,47,,,3.89763975,,21.98162737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T47,
D18P186001,R0,D18P186001R0,48,,,0.708661781,,7.545931844,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T48,
D18P186001,R0,D18P186001R0,49,,,0.314960805,,5.249344078,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T49,
D18P186001,R0,D18P186001R0,50,,,4.1338605,,20.34120737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T50,
D18P186001,R0,D18P186001R0,51,,,1.889764875,,13.12336,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T51,
D18P186001,R0,D18P186001R0,52,,,0.314960805,,5.249344078,,,,,,,,,,,,,,,,,,,D18P186001R0T52,
D18P186001,R0,D18P186001R0,53,,,0.629921609,,9.186351844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T53,
D18P186001,R0,D18P186001R0,54,,,0.354330891,,5.249344078,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T54,
D18P186001,R0,D18P186001R0,55,,,1.456693719,,11.81102369,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T55,
D18P186001,R0,D18P186001R0,56,,,2.047245125,,15.74803263,,,,,,,,,,,,,,,,,,,D18P186001R0T56,
D18P186001,R0,D18P186001R0,57,,,2.480316375,,17.06036737,,,,,,,,,,,,,,,,,,,D18P186001R0T57,
D18P186001,R0,D18P186001R0,58,,,1.968505,,15.41994737,,,,,,,,,,,,,,,,,,,D18P186001R0T58,
D18P186001,R0,D18P186001R0,59,,,3.93701,,20.99737631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T59,
D18P186001,R0,D18P186001R0,60,,,1.102362781,,8.2021,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T60,
D18P186001,R0,D18P186001R0,61,,,0.472441219,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T61,
D18P186001,R0,D18P186001R0,62,,,0.905512281,,9.514436313,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T62,
D18P186001,R0,D18P186001R0,63,,,0.944882438,,7.545931844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T63,
D18P186001,R0,D18P186001R0,64,,,1.574804,,8.530183687,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T64,
D18P186001,R0,D18P186001R0,65,,,0.472441219,,6.889763687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T65,
D18P186001,R0,D18P186001R0,66,,,5.15748325,,22.30971263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T66,
D18P186001,R0,D18P186001R0,67,,,5.35433375,,25.26246737,,,,,,,,,,,,,,,,,ABBA,29,D18P186001R0T67,
D18P186001,R0,D18P186001R0,68,,,0.511811281,,6.889763687,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T68,
D18P186001,R0,D18P186001R0,69,,,4.68504175,,20.34120737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T69,
D18P186001,R0,D18P186001R0,70,,,6.8897675,,25.91863631,,,,,,,,,,,,,,,,,ABBA,23,D18P186001R0T70,
D18P186001,R0,D18P186001R0,71,,,0.275590695,,5.249344078,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T71,
D18P186001,R0,D18P186001R0,72,,,4.606301625,,23.29396369,,,,,,,,,,,,,,,,,ABBA,20,D18P186001R0T72,
D18P186001,R0,D18P186001R0,73,,,0.511811281,,9.84252,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T73,
D18P186001,R0,D18P186001R0,74,,,0.275590695,,7.545931844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T74,
D18P186001,R0,D18P186001R0,75,,,0.393701,,4.92126,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T75,
D18P186001,R0,D18P186001R0,76,,,0.472441219,,8.530183687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T76,
D18P186001,R0,D18P186001R0,77,,,0.669291719,,5.577428156,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T77,
D18P186001,R0,D18P186001R0,78,,,0.354330891,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R0T78,
D18P186001,R0,D18P186001R0,79,,,4.409451125,,21.98162737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T79,
D18P186001,R0,D18P186001R0,80,,,7.12598825,,23.95013263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T80,
D18P186001,R0,D18P186001R0,81,,,4.724412,,24.93438369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R0T81,
D18P186001,R1,D18P186001R1,1,,,5.86614475,,25.59055263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T1,
D18P186001,R1,D18P186001R1,2,,,1.3779535,,12.13910816,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T2,
D18P186001,R1,D18P186001R1,3,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T3,
D18P186001,R1,D18P186001R1,4,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T4,
D18P186001,R1,D18P186001R1,5,,,0.236220609,,5.905511844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T5,
D18P186001,R1,D18P186001R1,6,,,4.1338605,,22.63779631,,,,,,,,,,,,,,,,,ABBA,31,D18P186001R1T6,
D18P186001,R1,D18P186001R1,7,,,3.425198625,,21.65354369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T7,
D18P186001,R1,D18P186001R1,9,,,2.480316375,,15.74803263,,,,,,,,,,,,,,,,,,,D18P186001R1T9,
D18P186001,R1,D18P186001R1,10,,,1.259843219,,15.41994737,,,,,,,,,,,,,,,,,,,D18P186001R1T10,
D18P186001,R1,D18P186001R1,11,,,1.574804,,15.74803263,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T11,
D18P186001,R1,D18P186001R1,12,,,4.88189225,,24.93438369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T12,
D18P186001,R1,D18P186001R1,13,,,3.89763975,,24.27821631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T13,
D18P186001,R1,D18P186001R1,14,,,1.3779535,,7.874016313,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T14,
D18P186001,R1,D18P186001R1,15,,,5.196853125,,26.24672,,,,,,,,,,,,,,,,,ABBA,33,D18P186001R1T15,
D18P186001,R1,D18P186001R1,16,,,4.055120375,,21.98162737,,,,,,,,,,,,,,,,,ABBA,33,D18P186001R1T16,
D18P186001,R1,D18P186001R1,17,,,1.220473062,,8.2021,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T17,
D18P186001,R1,D18P186001R1,18,,,0.9842525,,13.45144369,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T18,
D18P186001,R1,D18P186001R1,19,,,0.393701,,6.889763687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T19,
D18P186001,R1,D18P186001R1,20,,,0.472441219,,8.2021,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T20,
D18P186001,R1,D18P186001R1,21,,,2.716536938,,14.43569631,,,,,,,,,,,,,,,,,ABBA,27,D18P186001R1T21,
D18P186001,R1,D18P186001R1,22,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T22,
D18P186001,R1,D18P186001R1,23,,,1.181103,,10.49868816,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T23,
D18P186001,R1,D18P186001R1,24,,,5.000002625,,22.63779631,,,,,,,,,,,,,,,,,ABBA,30,D18P186001R1T24,
D18P186001,R1,D18P186001R1,25,,,4.88189225,,23.29396369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T25,
D18P186001,R1,D18P186001R1,26,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T26,
D18P186001,R1,D18P186001R1,27,,,1.023622562,,9.186351844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T27,
D18P186001,R1,D18P186001R1,28,,,4.330711,,22.96588,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T28,
D18P186001,R1,D18P186001R1,29,,,0.354330891,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T29,
D18P186001,R1,D18P186001R1,30,,,0.511811281,,9.186351844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T30,
D18P186001,R1,D18P186001R1,31,,,5.74803475,,23.95013263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T31,
D18P186001,R1,D18P186001R1,32,,,5.27559325,,24.27821631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T32,
D18P186001,R1,D18P186001R1,33,,,,,,,,,,,,,,,,,,,,,,,,D18P186001R1T33,
D18P186001,R1,D18P186001R1,34,,,0.944882438,,9.514436313,,,,,,,,,,,,,,,,,,,D18P186001R1T34,
D18P186001,R1,D18P186001R1,35,,,0.669291719,,9.186351844,,,,,,,,,,,,,,,,,,,D18P186001R1T35,
D18P186001,R1,D18P186001R1,36,,,1.062992719,,10.17060369,,,,,,,,,,,,,,,,,,,D18P186001R1T36,
D18P186001,R1,D18P186001R1,37,,,4.5275615,,21.65354369,,,,,,,,,,,,,,,,,ABBA,35,D18P186001R1T37,
D18P186001,R1,D18P186001R1,38,,,5.629924375,,26.24672,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T38,
D18P186001,R1,D18P186001R1,39,,,4.88189225,,22.96588,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T39,
D18P186001,R1,D18P186001R1,40,,,5.47244375,,27.88714,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T40,
D18P186001,R1,D18P186001R1,41,,,4.842522375,,27.88714,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T41,
D18P186001,R1,D18P186001R1,42,,,7.204728,,33.46456737,,,,,,,,,,,,,,,,,ABBA,29,D18P186001R1T42,
D18P186001,R1,D18P186001R1,43,,,4.842522375,,23.62204737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T43,
D18P186001,R1,D18P186001R1,44,,,4.606301625,,23.29396369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T44,
D18P186001,R1,D18P186001R1,45,,,0.748031891,,6.56168,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T45,
D18P186001,R1,D18P186001R1,46,,,1.3779535,,11.81102369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T46,
D18P186001,R1,D18P186001R1,47,,,4.37008125,,24.93438369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T47,
D18P186001,R1,D18P186001R1,48,,,0.9842525,,8.530183687,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T48,
D18P186001,R1,D18P186001R1,49,,,0.354330891,,5.249344078,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T49,
D18P186001,R1,D18P186001R1,50,,,5.07874275,,23.62204737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T50,
D18P186001,R1,D18P186001R1,51,,,2.401576062,,15.74803263,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T51,
D18P186001,R1,D18P186001R1,52,,,,,,,,,,,,,,,,,,,,,,,,D18P186001R1T52,
D18P186001,R1,D18P186001R1,53,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T53,
D18P186001,R1,D18P186001R1,54,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T54,
D18P186001,R1,D18P186001R1,55,,,1.614174062,,11.48294,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T55,
D18P186001,R1,D18P186001R1,56,,,2.401576062,,15.74803263,,,,,,,,,,,,,,,,,,,D18P186001R1T56,
D18P186001,R1,D18P186001R1,57,,,2.992127562,,17.06036737,,,,,,,,,,,,,,,,,,,D18P186001R1T57,
D18P186001,R1,D18P186001R1,58,,,2.204725562,,16.4042,,,,,,,,,,,,,,,,,,,D18P186001R1T58,
D18P186001,R1,D18P186001R1,59,,,4.96063275,,24.6063,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T59,
D18P186001,R1,D18P186001R1,60,,,1.456693719,,8.530183687,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T60,
D18P186001,R1,D18P186001R1,61,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T61,
D18P186001,R1,D18P186001R1,62,,,0.905512281,,10.49868816,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T62,
D18P186001,R1,D18P186001R1,63,,,1.023622562,,10.82677184,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T63,
D18P186001,R1,D18P186001R1,64,,,1.732284438,,10.17060369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T64,
D18P186001,R1,D18P186001R1,65,,,0.629921609,,8.530183687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T65,
D18P186001,R1,D18P186001R1,66,,,6.65354675,,22.96588,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T66,
D18P186001,R1,D18P186001R1,67,,,7.204728,,28.21522525,,,,,,,,,,,,,,,,,ABBA,34,D18P186001R1T67,
D18P186001,R1,D18P186001R1,68,,,1.259843219,,9.84252,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T68,
D18P186001,R1,D18P186001R1,69,,,5.66929425,,23.95013263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T69,
D18P186001,R1,D18P186001R1,70,,,7.6771695,,30.83989475,,,,,,,,,,,,,,,,,ABBA,28,D18P186001R1T70,
D18P186001,R1,D18P186001R1,71,,,0.5905515,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T71,
D18P186001,R1,D18P186001R1,72,,,5.629924375,,25.91863631,,,,,,,,,,,,,,,,,ABBA,25,D18P186001R1T72,
D18P186001,R1,D18P186001R1,73,,,0.275590695,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T73,
D18P186001,R1,D18P186001R1,74,,,0.314960805,,7.217848156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T74,
D18P186001,R1,D18P186001R1,75,,,0.354330891,,5.249344078,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T75,
D18P186001,R1,D18P186001R1,76,,,0.472441219,,7.545931844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T76,
D18P186001,R1,D18P186001R1,77,,,0.944882438,,7.217848156,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T77,
D18P186001,R1,D18P186001R1,78,,,0.393701,,5.905511844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T78,
D18P186001,R1,D18P186001R1,79,,,5.433073875,,23.62204737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T79,
D18P186001,R1,D18P186001R1,80,,,8.03150025,,26.24672,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T80,
D18P186001,R1,D18P186001R1,81,,,,,,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T81,
D18P186001,R1,D18P186001R1,82,,,0.157480402,,4.593175922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T82,
D18P186001,R1,D18P186001R1,83,,,0.118110305,,4.593175922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T83,
D18P186001,R1,D18P186001R1,84,,,0.118110305,,4.92126,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T84,
D18P186001,R1,D18P186001R1,85,,,0.118110305,,4.92126,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T85,
D18P186001,R1,D18P186001R1,86,,,0.118110305,,4.92126,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T86,
D18P186001,R1,D18P186001R1,87,,,0.157480402,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T87,
D18P186001,R1,D18P186001R1,88,,,0.275590695,,6.56168,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T88,
D18P186001,R1,D18P186001R1,89,,,1.102362781,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T89,
D18P186001,R1,D18P186001R1,90,,,0.314960805,,6.889763687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T90,
D18P186001,R1,D18P186001R1,91,,,0.1968505,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T91,
D18P186001,R1,D18P186001R1,92,,,0.629921609,,5.577428156,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T92,
D18P186001,R1,D18P186001R1,93,,,0.1968505,,4.593175922,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T93,
D18P186001,R1,D18P186001R1,94,,,0.393701,,5.905511844,,,,,,,,,,,,,,,,,ABBA,,D18P186001R1T94,
D18P186001,R1,D18P186001R1,95,,,0.314960805,,6.56168,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T95,
D18P186001,R1,D18P186001R1,96,,,0.393701,,7.545931844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T96,
D18P186001,R1,D18P186001R1,97,,,0.275590695,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T97,
D18P186001,R1,D18P186001R1,98,,,0.393701,,6.889763687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T98,
D18P186001,R1,D18P186001R1,99,,,0.354330891,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T99,
D18P186001,R1,D18P186001R1,100,,,0.354330891,,6.233595922,,,,,,,,,,,,,,,,,BEPA,,D18P186001R1T100,
D18P186001,R2,D18P186001R2,1,,,6.3779565,,26.90288737,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T1,
D18P186001,R2,D18P186001R2,2,,,1.417323562,,12.46719184,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T2,
D18P186001,R2,D18P186001R2,3,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T3,
D18P186001,R2,D18P186001R2,4,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T4,
D18P186001,R2,D18P186001R2,5,,,0.314960805,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T5,
D18P186001,R2,D18P186001R2,6,,,4.251970875,,22.96588,,,,,,,,,,,,,,,,,ABBA,33,D18P186001R2T6,
D18P186001,R2,D18P186001R2,7,,,3.58267925,,22.63779631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T7,
D18P186001,R2,D18P186001R2,8,,,,,,,,,,,,,,,,,,,,,,,,D18P186001R2T8,
D18P186001,R2,D18P186001R2,9,,,2.5590565,,17.06036737,,,,,,,,,,,,,,,,,,,D18P186001R2T9,
D18P186001,R2,D18P186001R2,10,,,1.220473062,,15.09186369,,,,,,,,,,,,,,,,,,,D18P186001R2T10,
D18P186001,R2,D18P186001R2,11,,,1.614174062,,15.74803263,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T11,
D18P186001,R2,D18P186001R2,12,,,5.07874275,,24.93438369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T12,
D18P186001,R2,D18P186001R2,13,,,4.1338605,,25.59055263,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T13,
D18P186001,R2,D18P186001R2,14,,,1.3779535,,9.186351844,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T14,
D18P186001,R2,D18P186001R2,15,,,5.433073875,,26.24672,,,,,,,,,,,,,,,,,ABBA,35,D18P186001R2T15,
D18P186001,R2,D18P186001R2,16,,,4.37008125,,22.30971263,,,,,,,,,,,,,,,,,ABBA,35,D18P186001R2T16,
D18P186001,R2,D18P186001R2,17,,,1.220473062,,8.2021,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T17,
D18P186001,R2,D18P186001R2,18,,,1.181103,,14.10761263,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T18,
D18P186001,R2,D18P186001R2,19,,,0.393701,,7.545931844,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T19,
D18P186001,R2,D18P186001R2,20,,,0.551181391,,8.530183687,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T20,
D18P186001,R2,D18P186001R2,21,,,2.834647125,,15.09186369,,,,,,,,,,,,,,,,,ABBA,29,D18P186001R2T21,
D18P186001,R2,D18P186001R2,22,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T22,
D18P186001,R2,D18P186001R2,23,,,1.259843219,,10.82677184,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T23,
D18P186001,R2,D18P186001R2,24,,,5.3149635,,23.95013263,,,,,,,,,,,,,,,,,ABBA,32,D18P186001R2T24,
D18P186001,R2,D18P186001R2,25,,,5.039372875,,23.29396369,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T25,
D18P186001,R2,D18P186001R2,26,,,,,,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T26,
D18P186001,R2,D18P186001R2,27,,,0.9842525,,11.81102369,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T27,
D18P186001,R2,D18P186001R2,28,,,4.48819125,,24.27821631,,,,,,,,,,,,,,,,,ABBA,,D18P186001R2T28,
D18P186001,R2,D18P186001R2,29,,,0.393701,,5.577428156,,,,,,,,,,,,,,,,,BEPA,,D18P186001R2T29,
For traversing dataframe either one of the options can be used.But its not advisable to update a dataframe in its own loop.
for (i in seq_len(nrow(FVS_TreeInit))){
print(i)
}
for (i in 1: nrow(FVS_TreeInit)){
print(i)
}
Vectorizing the updates is prefered as in dplyr
library(dplyr)
FVS_TreeInit<-FVS_TreeInit %>%
mutate(StandPlotTree_ID_Past = case_when(
Plot_ID=="R1" ~ paste(`Stand_ID`,"R0T",`Tree_ID`,sep=""),
Plot_ID=="R2" ~ paste(`Stand_ID`,"R1T",`Tree_ID`,sep=""), # fill rest of the Plot_ID logic
TRUE ~ "NA" # this is the else catch-all
))
I prefer joining to a lookup table for operations like this - I find it much easier to debug, audit, edit, etc.
## build the lookup table
lookup <- tribble(
~Plot_ID, ~infix,
"R8", "R7T",
"R7", "R6T",
"R6", "R5T",
"R5", "R4T",
"R4", "R3T",
"R3", "R2T",
"R2", "R1T",
"R1", "R0T"
)
## join and paste
library(dplyr)
FVS_TreeInit <-
FVS_TreeInit %>%
left_join(lookup, by = "Plot_ID") %>%
mutate(StandPlotTree_ID_Past = paste0(Stand_ID, infix, Tree_ID))