[R] multiple character matching within a string

Murad Nayal mn216 at columbia.edu
Sat Oct 11 22:31:29 CEST 2003



Hello all,

I need to count the number of times certain characters occur in a
string. The only way I have found so far to accomplish this is by using
strsplit i.e.

my.string <- "DDDRRHIH"
my.char   <- "D"
num.char <- -1 + length(unlist(strsplit(my.string,my.char)))

now you probably won't be surprised if I say that this has proven to be
extremely slow (I am not sure exactly why though, is it because strsplit
creates new list for every call?). Is there an alternative way to do
this short of going to compiled code?

many thanks,





-- 
Murad Nayal M.D. Ph.D.
Department of Biochemistry and Molecular Biophysics
College of Physicians and Surgeons of Columbia University
630 West 168th Street. New York, NY 10032
Tel: 212-305-6884	Fax: 212-305-6926




More information about the R-help mailing list