[R] Number of occurences of a character in a string
Christian Raschke
crasch2 at tigers.lsu.edu
Mon Oct 11 06:33:54 CEST 2010
> length(gregexpr(";", b)[[1]])
[1] 5
This works as long as the substrings you are searching for don't overlap.
Christian
On 10/10/2010 11:18 PM, Santosh Srinivas wrote:
> New to R ... which is a function to most effectively search the number of occurrences of a character in a string?
>
> b<- c("jkhrikujhj345hi5hiklfjsdkljfksdio324j';;'lfd;g'lkfit34'5;435l;43'5k")
>
> I want the number of semi-colons ";" in b?
>
> Thanks.
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Christian Raschke
Department of Economics
and
ISDS Research Lab (HSRG)
Louisiana State University
Patrick Taylor Hall, Rm 2128
Baton Rouge, LA 70803
crasch2 at lsu.edu
More information about the R-help
mailing list