Dear R users,
 
Thanks for your help
The recomendations were exaclty what I was searching. 
Bellow the one I will use for my script.
Thanks again,
jose
 
nchar(xx)
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 4 4 4 4 4 4 4 4
 [75] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
 
z1 <- rep("000000000", times=length(xx))
z2 <- substr(z1, 1, 9 - nchar(xx))
xx <- paste(z2, xx, sep="")
xx<-substring(xx, 6, 9)
nchar(xx)
 
[1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
 [38] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
 [75] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

 
> Date: Wed, 5 Jan 2011 19:50:28 +0100
> From: savi...@cs.cas.cz
> To: r-help@r-project.org
> Subject: Re: [R] vector of character with unequal width
> 
> 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.
> 
> ______________________________________________
> 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.
                                          
        [[alternative HTML version deleted]]

______________________________________________
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