Message-ID: <20110105185028.GA16539@cs.cas.cz>
Date: 2011-01-05T18:50:28Z
From: Petr Savicky
Subject: vector of character with unequal width
In-Reply-To: <SNT125-W45CBD1EE60A3E5123C8BABB6090@phx.gbl>
On Wed, Jan 05, 2011 at 03:50:13PM +0000, jose Bartolomei wrote:
[...]
>
> I was thinking to create a character vector of 0's 9-nchar(xx).
> Then paste it to xx.
> 9-nchar(xx)
> [1] 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
> [38] 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 6 6 6 6 6 5 5 5 5 5 5 5 5
> [75] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 ......1
>
>
>
>
> Nevertheless, I have not been able to create this vector nor I do not know if this is the best option.
Did you consider something like the following?
xx <- c("abc", "abcd", "abcde")
z1 <- rep("000000000", times=length(xx))
z2 <- substr(z1, 1, 9 - nchar(xx))
yy <- paste(z2, xx, sep="")
cbind(yy)
# yy
#[1,] "000000abc"
#[2,] "00000abcd"
#[3,] "0000abcde"
Petr Savicky.