[R] Working with string
Marc Schwartz
marc_schwartz at me.com
Thu Mar 14 16:02:43 CET 2013
On Mar 14, 2013, at 9:42 AM, Christofer Bogaso <bogaso.christofer at gmail.com> wrote:
> Hello again,
>
> Let say I have following string:
>
> Vec <- c("sada", "asdsa", "sa")
>
> Now I want to make each element of this vector with equal length.
> Basically I want following vector:
>
> c("sada ", "asdsa", "sa ")
>
> Therefore we can get:
>
>> nchar(c("sada ", "asdsa", "sa "))
> [1] 5 5 5
>
>
> Is there any possiblity that we can do it programetically? Because I
> need to handle a really big vector.
>
> Thanks for your help.
?format will by default, left justify and pad with spaces to the longest length element in the character vector:
Vec <- c("sada", "asdsa", "sa")
> format(Vec)
[1] "sada " "asdsa" "sa "
Regards,
Marc Schwartz
More information about the R-help
mailing list