filter list of words within a variable

I am working on clinical records in R. I am trying to create a list of words that can be found in the variable "examination text" to identify the number of observations including at least one of the words. I have created a new column "status" to categorise an observation as "unaffected"=0 and "affected"=1, with "affected" being those that contain the list of words found in "examination text".
What function/s do I use to create this list of words found in "examination text"?

Give an example of text you want to check for.

You can use grepl to work with it.
You can add the list of words and then check for each word with your 'examination text' variable and update the status category accordingly.

For e.g.

words<-list('throat', 'blood pressure', 'temperature', 'ear', 'ecg')
for(names in df$examination.text)
      for(j in seq(1, length(words))
1 Like

An example of the "Examination.Text"

> head(SF$"Examination.Text")
[1] "Boarding 22_12_2017 - 30_12_2017. Tail can get sore. Own  bed."  

[4] "Reason: Follow Up History: see previous re lame left hind walking well on hind leg now Examination: joint filling and swelling soft tissue left hock much reduced still significant boney changes both hocks and carpi Assessment: djd consider cartilage modifyers Plan: zydax 0.15 ml scut continue c metacam sid 3 days then stop see weekly x 4  inj"

Some words I would include are "lame" | "fracture" | "joint" etc. To determine which clinic visits are associated with the disease presentation I'm interested in i.e. "affected".

I've tried creating words<-list["lame","fracture"] but no luck. I'm also trying to use or symbol as only one word needs to be found in the examination text to classify as "affected"

> words<-list["lame","fracture"]
Error in list["lame", "fracture"] : 
  object of type 'builtin' is not subsettable

I had made an error. In creating list you have to use parenthesis instead of square brackets

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.