Skip to content
Prev 246757 / 398502 Next

vector of character with unequal width

On Fri, Jan 07, 2011 at 02:55:18PM +0000, jose Bartolomei wrote:
Let me suggest a slightly simpler code, which produces the same
output, if the input has length at most 9.

  xx <- c("abc", "abcd", "abcde")

  xx <- paste("000", xx, sep="")
  xx <- substr(xx, nchar(xx) - 3, nchar(xx))

  cbind(xx)
  #     xx    
  #[1,] "0abc"
  #[2,] "abcd"
  #[3,] "bcde"

Petr Savicky.