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 charAt(string,"."), i.e. > the position of the period in the word, but I can't seem to find a charAt > command in R.
See ?regexpr But a simpler solution is sub("\\..*", "", string). -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.