[R] Regression expression to delete one or more spaces at end of string
wdunlap at tibco.com
Tue Aug 2 18:57:12 CEST 2016
First, use [[:blank:]] instead of [:blank:]. that latter matches colon, b,
a, n, and k, the former whitespace.
Second, put + after [[:blank:]] to match one or more of them.
On Tue, Aug 2, 2016 at 9:46 AM, Dennis Fisher <fisher at plessthan.com> wrote:
> R 3.3.1
> OS X
> I have encountered an unexpected regex problem
> I have read an Excel file into R using the readxl package. Columns names
> COLNAMES <- c("Study ID", "Test and Biological Matrix", "Subject
> No. ", "Collection Date",
> "Collection Time", "Scheduled Time Point", "Concentration", "Concentration
> "LLOQ", "ULOQ", "Comment”)
> As you can see, there is a trailing space in “Subject No. “. I would like
> to delete that space. The following works:
> sub(“ $”, “”, COLNAMES)
> However, I would like a more general approach that removes any trailing
> I tried variations such as:
> sub("[:blank:]$", "", COLNAMES)
> (also, without the $ and ‘space' instead of ‘blank') without success — to
> my surprise, characters other than the trailing space were deleted but the
> trailing space remained.
> Guidance on the correct syntax would be appreciated.
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone / Fax: 1-866-PLessThan (1-866-753-7784)
> R-help at 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