You can use grepl()for this. I would go for str_detect() from the
library stringr. It uses grepl() under the bonnet but is probably easier
to use.
library(stringr)
x <- c("they", "their", "this", "that", "them", "themselves")
str_match(x,'the')
[1] TRUE TRUE FALSE FALSE TRUE TRUE
str_detect(x,'em')
[1] FALSE FALSE FALSE FALSE TRUE TRUE
Cheers,
Christophe
--
Dr Christophe Ladroue
Computer Science Department
Warwick University, UK
gpglot2 and Shiny in 2 hours: http://bit.ly/1lpzVo1
On 23/04/14 17:20, Douglas Thompson wrote:
> Dear Allstat,
>
> Does anyone know of any existing R functions which can recognise
> fragments of words amongst a given vector of words?
> Suppose I had a vector e.g., ("they", "their", "this", "that", "them",
> "themselves"). What I’d like to know is when 'the' appears as a fragment,
>
> i.e., returns an indicator c(1, 1, 0, 0, 1, 1)
>
> or perhaps 'em',
>
> i.e., returns c(0, 0, 0, 0, 1, 1).
>
> Thanks in advance for any help.
>
> Doug
>
> --
> Douglas Thompson
> PhD student (Room 316)
> Centre for Population Health Sciences
> University of Edinburgh Medical School
> Teviot Place
> Edinburgh
> EH8 9AG
> Tel. 0131 650 6964
>
> You may leave the list at any time by sending the command
>
> SIGNOFF allstat
>
> to [log in to unmask] <mailto:[log in to unmask]>, leaving the
> subject line blank.
>
>
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
> You may leave the list at any time by sending the command
>
> SIGNOFF allstat
>
> to [log in to unmask], leaving the subject line blank.
>
You may leave the list at any time by sending the command
SIGNOFF allstat
to [log in to unmask], leaving the subject line blank.
|