[R] Character position command
ggrothendieck at gmail.com
Sun Aug 26 03:46:05 CEST 2007
See ?regexpr to get the position; however, using sub we could remove
the dot and everything after it in one go. See ?regexp and ?sub .
Also there are some links to info on regular expressions in the Links
box on this page:
> n <- regexpr(".", "apples.pears", fixed = TRUE)
> substr("apples.pear", 1, n-1)
> sub("[.].*", "", "apples.pears")
On 8/25/07, Mitchell Hoffman <mh8675309 at gmail.com> wrote:
> This is a very simple question, so I apologize I couldn't find it online:
> I want to shorten the string 'apples.pears' to 'apples'.
> For x above, I would like to have a command like charAt(string,"."), i.e.
> the position of the period in the word, but I can't seem to find a charAt
> command in R.
> Thank you.
> [[alternative HTML version deleted]]
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help