HI,
May be this helps:
for(i in letters) {
  n <- n+1
  x[n,] <- c(i, n)
cat("loop", n, "\n")
}
x
#or
for(i in seq_along(letters)) {
  n <- n+1
  x[n,] <- c(letters[i], n)
cat("loop", i, "\n")
}
x

A.K.


#How can I add the loop counter in #2 to the loop in #1.?
#***************
#1.
x <- matrix( , ncol = 2, nrow = 26) # empty matrix
n <- 0     #set n to 0
for(i in letters) {
  n <- n+1
  x[n,] <- c(i, n)
}
x
#***********
#2.
for (i in 1:10) {
cat("loop", i, "\n")
}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to