Richard In reply to your “first response”, the text was originally in a Word document and it did NOT contain the errant spaces. I used read_docx in the textreadr package to access the text. The spaces were added during that step. I am copying the maintainer of that package to see if he has any idea as to the source.
Thanks for your regular expression suggestion. Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone / Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com <http://www.plessthan.com/> > On Jul 28, 2020, at 5:11 PM, Richard O'Keefe <rao...@gmail.com> wrote: > > The first response has to be "how did the spaces get there > in the first place?" Can you fix the process that creates > the data? If the process sometimes generates one extra > space, are you sure it never generates two? > > But let's treat this purely as a regular expression > problem, where if there is a space before a dot you want > to delete the first. In vi(1) you would do > > s/^\([^ .]*\) \([^.]*\)/\1\2/ > > but apparently there is *supposed* to be a space before > the 01, so it is only when there are two or more spaces > that one should be deleted, so we'd want > > s/^\([^ .]*\) \([^ .]* \)/\1\2/ > > I leave converting that to R as an exercise for the reader. > > > > > On Wed, 29 Jul 2020 at 08:20, Dennis Fisher <fis...@plessthan.com > <mailto:fis...@plessthan.com>> wrote: > R 4.0.2 > OS X > > Colleagues > > I have strings that contain a space in an unexpected location. The intended > string is: > “STRING 01. Remainder of the string" > However, variants are: > “STR ING 01. Remainder of the string" > “STRIN G 01. Remainder of the string" > > I would like a general approach to deleting a space, but only if it appears > before the period. Any suggestions on a regular expression for this? > > Dennis > > Dennis Fisher MD > P < (The "P Less Than" Company) > Phone / Fax: 1-866-PLessThan (1-866-753-7784) > www.PLessThan.com <http://www.plessthan.com/> <http://www.plessthan.com/ > <http://www.plessthan.com/>> > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To > UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > <https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > <http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.