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

From: roger bos <roger.bos_at_gmail.com>
Date: Tue 25 Oct 2005 - 23:08:09 EST

Thanks to everyone for the gsub function. The white spaces were generated by reading in the file, but its a fixed width file and I only need some of the columns, so this was the easiest way to do it.  Thanks,
 Roger

 On 10/25/05, Marc Schwartz <MSchwartz@mn.rr.com> wrote:
>
> On Tue, 2005-10-25 at 08:51 -0400, 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?
> > Thanks,
> > Roger
>
> Roger,
>
> See the next to last set of examples in ?sub.
>
> > a <- c("ABM ", "AFCE ", "AG ", "ATG ")
> > a
> [1] "ABM " "AFCE " "AG " "ATG "
>
> > a.new <- sub(' +$', '', a)
> > a.new
> [1] "ABM" "AFCE" "AG" "ATG"
>
>
> Also, if this data was generated using read.table() or one of it's
> variants, note the use of the 'strip.white' argument in ?read.table.
>
> HTH,
>
> Marc Schwartz
>
>
>

        [[alternative HTML version deleted]]



R-help@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 Received on Tue Oct 25 23:49:14 2005

This archive was generated by hypermail 2.1.8 : Wed 26 Oct 2005 - 00:12:47 EST