[R] Working with string

arun smartpink111 at yahoo.com
Thu Mar 14 16:01:29 CET 2013


library(stringr)
 str_pad(Vec,5,"right")
#[1] "sada " "asdsa" "sa   "


#or
str_pad(Vec,max(nchar(Vec)),"right")
#[1] "sada " "asdsa" "sa   "



str_count(str_pad(Vec,5,"right"),"")
#[1] 5 5 5
A.K.


----- Original Message -----
From: Christofer Bogaso <bogaso.christofer at gmail.com>
To: r-help <r-help at r-project.org>
Cc: 
Sent: Thursday, March 14, 2013 10:42 AM
Subject: [R] Working with string

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.

______________________________________________
R-help at 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.




More information about the R-help mailing list