Ernesto Jardim <ernesto at ipimar.pt> writes:> Hi > > I've imported some data from a oracle database and the strings have a > lot of blank space (because of the delimiter). I want to remove these > blanks space with something similar to a trim function. > > I don't find a trim function or something similar. Can someone give a > help on this ?If you want to remove trailing blanks you can use sub with the regular expression ' +$'.> str = 'Now is the time ' > sub(' +$', '', str, extended = TRUE)[1] "Now is the time" I had hoped you could use '\s+$' or '\\s+$' but that doesn't seem to work. I guess we would need the perl regular expression library, of which there has been some discussion, to do that. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 9 May 2002, Ernesto Jardim wrote:> I've imported some data from a oracle database and the strings have a > lot of blank space (because of the delimiter). I want to remove these > blanks space with something similar to a trim function. > > I don't find a trim function or something similar. Can someone give a > help on this ?sub() can do this (and far, far more). Do you want to trim leading or trailing spaces or all spaces or what. For trailing spaces sub(" +$", "", x) will do what you want. For spaces both ends and no embedded spaces sub(" *([^ ]+) *", "\\1", x) and so on. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi I've imported some data from a oracle database and the strings have a lot of blank space (because of the delimiter). I want to remove these blanks space with something similar to a trim function. I don't find a trim function or something similar. Can someone give a help on this ? Thanks EJ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._