[R] Can anyone please tell me how to strip the white spaces from a character vector?

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Oct 25 15:14:17 CEST 2005


roger bos wrote:

> for example:
> 
>>a$tic[1:10]
> 
> [1] "AIR " "ABCB " "ABXA " "ACMR " "ADCT " "ADEX "
> [7] "ABM " "AFCE " "AG " "ATG "
>  Can anyone please tell me how to strip the white spaces from a$tic?


Not beeing an expert for regular expressions, I'd try
    sub(" *$", "", sub("^ *", "", a$tic))
to strip from beginnings and ends but there may be far better approches.
In order to remove *all* blanks, try
    gsub(" ", "", a$tic)

Uwe Ligges


>  Thanks,
>  Roger
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list