[R] substr gives empty output

Luigi Marongiu marongiu.luigi at gmail.com
Sun Jan 21 09:59:02 CET 2018


Dear all,
I have a string, let's say "testing", and I would like to extract in
sequence each letter (character) from it. But when I use substr() I only
properly get the first character, the rest is empty (""). What am I getting
wrong?
For example, I have this code:

>>>
x <- "testing"
k <- nchar(x)
for (i in 1:k) {
  y <- substr(x, i, 1)
  print(y)
}

	[[alternative HTML version deleted]]



More information about the R-help mailing list