Hi Doug,
You want to use grepl:
> words <- c("they", "their", "this", "that", "them", "themselves")
> grepl("the", words)
[1] TRUE TRUE FALSE FALSE TRUE TRUE
> grepl("em", words)
[1] FALSE FALSE FALSE FALSE TRUE TRUE
Marco
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.
--
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.
|