[R] Removing a space from a string
r@oknz @end|ng |rom gm@||@com
Wed Jul 29 02:11:11 CEST 2020
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 <fisher using plessthan.com> wrote:
> R 4.0.2
> OS X
> 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
> 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/>
> [[alternative HTML version deleted]]
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help