You need to declare
tmpvarname1
and
tmpvarname2
in the global space so they can be accessed inside and outside of the loop. You also need to use the global assignment operator (
<<-
) to update them inside the loop.
tmpvarname1 <- tmpvarname2 <- 0
while(listlength>0) {
if (parameters[pcount]>1000){
tmpvarname1 <<- assign(paste("sn", sncount, sep = ""),parameters[pcount])
sncount <- sncount +1
}
if (parameters[pcount]<=99){
tmpvarname2 <<- assign(paste("tn", tncount, sep = ""),parameters[pcount])
tncount <- tncount +1
}
listlength <- listlength-1
pcount <- pcount +1
}
tmpvarname1
tmpvarname2
You may want to do the same with
sncount
,
tncount
and
pcount
.
For further details see
Scope of Variable in R - GeeksforGeeks[
^].