[R] How to left or right truncate a character string?
Mark Na
mtb954 at gmail.com
Tue Dec 14 21:27:49 CET 2010
Hi R-helpers,
I have a character string, for example:
"lm(y ~ X2 + X3 + X4)"
from which I would like to strip off the leading and trailing
quotation marks resulting in this:
lm(y ~ X2 + X3 + X4)
I have tried using gsub() but I can't figure out how to specify the
quotation mark using a regular expression.
Alternatively, I would like a function that lets me delete the leading
(or trailing) X characters, and in this case X=1 (but it could be used
more flexibly to delete several leading or trailing characters).
I would appreciate help with either of these potential solutions (gsub
and regex, or delete leading/trailing characters).
Many thanks!
Mark
More information about the R-help
mailing list