0
`y <- c()

for( position in c("cannon","jackson","benford","paws","moxie") ) {
n <- nchar(position)
y[position] <- letters[n]
}

y

n

What I am essentially trying to do is write the code that is behind the scenes of this for loop but I am running into issues as to where to go with it. What would this for loop expanded look like?

1 Answers1

0
  1. position <- "cannon"

    • n <- nchar(position)n <- nchar("cannon")n <- 6
    • y[position] <- letters[n]y["cannon"] <- letters[6]j["cannon"] <- "f"
  2. position <- "jackson"

    • n <- nchar(position)n <- nchar("jackson")n <- 7
    • y[position] <- letters[n]y["jackson"] <- letters[7]j["jackson"] <- "g"

etc

r2evans
  • 141,215
  • 6
  • 77
  • 149