[R] Removing trailing spaces

Tom Mulholland tmulholland at bigpond.com
Wed Dec 22 00:26:35 CET 2004


I generally use sub like so sub(" *$","",vector)


 > x <- c("this one   ","and that one ","plus this")
 > sub(" *$","",x)
[1] "this one"     "and that one" "plus this"
 >

Tom

Patrick Connolly wrote:
> Some years ago when I used S-PLUS, I seem to remember, there was a
> discussion about a simple method of removing trailing spaces from
> vector elements.  I'd be fairly sure the same would work in R, but I
> can't find any mention of anything like it in the R archives or with
> help.search().
> 
> There are ways I could do it with substring(), but I seem to remember
> there was something more elegant.  I can find the strip function in
> the clim.pact package, but that trims everything after the first space
> which is not useful in this case.
> 
> Someone please refresh my memory.
> 
> TIA
> 


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.




More information about the R-help mailing list