s-luppescu@uchicago.edu
2001-May-31 23:12 UTC
[R] Trimming blanks from the ends of strings
This is pretty mundane, but I much appreciate the help. I have character variables that I have read in from 40-character-wide fields. I want to remove the spaces from the ends so I can use them right justified (adj=1) as labels on the vertical axis of a graph. Thanks. ______________________________________________________________________ Stuart Luppescu -=-=- University of Chicago $(B:MJ8$HCRF`H~$NIc(B -=-=- s-luppescu at uchicago.edu http://www.consortium-chicago.org/people/sl.html http://musuko.uchicago.edu/pubkey.asc for PGP Public Key ICQ #21172047 AIM: psycho7070 Man is a military animal, glories in gunpowder, and loves parade. -- P.J. Bailey>> Sent on 31-May-2001 at 18:01:39 with xfmail-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
s-luppescu at uchicago.edu wrote:> > This is pretty mundane, but I much appreciate the help. I have character > variables that I have read in from 40-character-wide fields. I want to remove > the spaces from the ends so I can use them right justified (adj=1) as labels on > the vertical axis of a graph.Something like sub("^ *", "", sub(" *$", "", x)) should do the trick. E.g. > sub("^ *", "", sub(" *$", "", " padded ")) [1] "padded" -- Ross Ihaka Email: ihaka at stat.auckland.ac.nz Department of Statistics Phone: (64-9) 373-7599 x 5054 University of Auckland Fax: (64-9) 373-7018 Private Bag 92019, Auckland New Zealand -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> I want to remove > the spaces from the ends so I can use them right justified (adj=1) as labels on > the vertical axis of a graph.gsub("[ ]*$","",my.data.object) Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._