roger bos
2005-Oct-25 12:51 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
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 [[alternative HTML version deleted]]
cgb@datanalytics.com
2005-Oct-25 13:01 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
Quoting roger bos <roger.bos at gmail.com>:> 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 > > [[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 >> a <- c("ab ", "cd", "ef ") > gsub(" ", "", a)[1] "ab" "cd" "ef" Carlos J. Gil Bellosta http://www.datanalytics.com
Sean Davis
2005-Oct-25 13:03 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
On 10/25/05 8:51 AM, "roger bos" <roger.bos at gmail.com> 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 > > [[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 >See ?gsub. gsub(' ','',a$tic) Sean
Marc Schwartz
2005-Oct-25 13:06 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
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, > RogerRoger, 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
Romain Francois
2005-Oct-25 13:09 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
Le 25.10.2005 14:51, roger bos a ??crit :>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 > >gsub(' ','',a$tic) -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques +---------------------------------------------------------------+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---------------------------------------------------------------+
Wuming Gong
2005-Oct-25 13:10 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
Try trim() in gdata package. Wuming On 10/25/05, roger bos <roger.bos at gmail.com> 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 > > [[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 >
Uwe Ligges
2005-Oct-25 13:14 UTC
[R] Can anyone please tell me how to strip the white spaces from a character vector?
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
Dimitris Rizopoulos
2005-Oct-25 13:14 UTC
[R] Can anyone please tell me how to strip the white spaces from acharacter vector?
one way is to use strsplit(), i.e.,
xx <- c("AIR ", "ABCB ", "ABXA ", "ACMR
", "ADCT ", "ADEX ")
unlist(strsplit(xx, " "))
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "roger bos" <roger.bos at gmail.com>
To: "(r-help at stat.math.ethz.ch.)" <R-help at
stat.math.ethz.ch>
Sent: Tuesday, October 25, 2005 2:51 PM
Subject: [R] Can anyone please tell me how to strip the white spaces
from acharacter vector?
> 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
>
> [[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
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Stefano Calza
2005-Oct-25 14:42 UTC
[R] Can anyone please tell me how to strip the white spaces from acharacter vector?
What about
xx <- c("AIR ", "ABCB ", "ABXA ", "ACMR
", "ADCT ", "ADEX "," AAA")
xx=gsub("[[:blank:]]","",xx)
Stefano
On Tue, Oct 25, 2005 at 03:14:39PM +0200, Dimitris Rizopoulos wrote:
<Dimitris>one way is to use strsplit(), i.e.,
<Dimitris>
<Dimitris>xx <- c("AIR ", "ABCB ", "ABXA
", "ACMR ", "ADCT ", "ADEX ")
<Dimitris>
<Dimitris>Best,
<Dimitris>Dimitris
<Dimitris>
<Dimitris>----
<Dimitris>Dimitris Rizopoulos
<Dimitris>Ph.D. Student
<Dimitris>Biostatistical Centre
<Dimitris>School of Public Health
<Dimitris>Catholic University of Leuven
<Dimitris>
<Dimitris>Address: Kapucijnenvoer 35, Leuven, Belgium
<Dimitris>Tel: +32/(0)16/336899
<Dimitris>Fax: +32/(0)16/337015
<Dimitris>Web: http://www.med.kuleuven.be/biostat/
<Dimitris> http://www.student.kuleuven.be/~m0390867/dimitris.htm
<Dimitris>
<Dimitris>
<Dimitris>----- Original Message -----
<Dimitris>From: "roger bos" <roger.bos at gmail.com>
<Dimitris>To: "(r-help at stat.math.ethz.ch.)" <R-help at
stat.math.ethz.ch>
<Dimitris>Sent: Tuesday, October 25, 2005 2:51 PM
<Dimitris>Subject: [R] Can anyone please tell me how to strip the white
spaces
<Dimitris>from acharacter vector?
<Dimitris>
<Dimitris>
<Dimitris>> for example:
<Dimitris>>> a$tic[1:10]
<Dimitris>> [1] "AIR " "ABCB " "ABXA "
"ACMR " "ADCT " "ADEX "
<Dimitris>> [7] "ABM " "AFCE " "AG "
"ATG "
<Dimitris>> Can anyone please tell me how to strip the white spaces
from a$tic?
<Dimitris>> Thanks,
<Dimitris>> Roger
<Dimitris>>
<Dimitris>> [[alternative HTML version deleted]]
<Dimitris>>
<Dimitris>> ______________________________________________
<Dimitris>> R-help at stat.math.ethz.ch mailing list
<Dimitris>> https://stat.ethz.ch/mailman/listinfo/r-help
<Dimitris>> PLEASE do read the posting guide!
<Dimitris>> http://www.R-project.org/posting-guide.html
<Dimitris>>
<Dimitris>
<Dimitris>
<Dimitris>Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
<Dimitris>
<Dimitris>______________________________________________
<Dimitris>R-help at stat.math.ethz.ch mailing list
<Dimitris>https://stat.ethz.ch/mailman/listinfo/r-help
<Dimitris>PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
Apparently Analagous Threads
- Can anyone please tell me how to strip the white spaces f rom a character vector?
- [ANNOUNCE] Samba 3.3.0pre2 Available for Download
- [ANNOUNCE] Samba 3.3.0pre2 Available for Download
- [PATCH 23/23] nvc0: implement support for maxwell texture headers
- [ANNOUNCE] Samba 3.3.0rc2 Available for Download