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'.
string='apples.pears'
string1=substr(string,0,x)
For x above, I would like to have a command like charAt(string,.), i.e.
the position of the period in the word, but
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:
http://gsubfn.googlecode.com
n - regexpr(., apples.pears, fixed = TRUE)
On Sat, 25 Aug 2007, Mitchell Hoffman 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'.
string='apples.pears'
string1=substr(string,0,x)
For x above, I would like to have a command like