Re: [R] Number of occurences of a character in a string

2010-10-11 Thread Ted Harding
How about: sum(unlist(strsplit(b,NULL))==";") # [1] 5 (More transparent, at least to me ... ). See '?strsplit', and note what is said under "Value". Ted. On 11-Oct-10 04:35:43, Michael Sumner wrote: > Literally: > > length( gregexpr(";", b)[[1]]) > > But more generally, in case b has more

Re: [R] Number of occurences of a character in a string

2010-10-10 Thread Michael Sumner
Literally: length( gregexpr(";", b)[[1]]) But more generally, in case b has more than one element: sapply(gregexpr(";", b), length) ?gregexpr On Mon, Oct 11, 2010 at 3:18 PM, Santosh Srinivas < santosh.srini...@gmail.com> wrote: > New to R ... which is a function to most effectively search

Re: [R] Number of occurences of a character in a string

2010-10-10 Thread Christian Raschke
> 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

[R] Number of occurences of a character in a string

2010-10-10 Thread Santosh Srinivas
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-he