Hello! I have a list of medical organizations types which looks like this:
list <- c("hospital", "center", "polyclinic", "dispencer")
I also have a dataframe with the name of the organization and the defined type which looks like this (there is an extreme case presented here which needs a solution):
| Name | Type |
| -------- | -------------- |
| cure center state hospital | hospital |
| state polyclinic cure center | center |
| state hospital main dispancer| dispancer|
| first hospital number one | hospital |
As you can see some names have 2 types of organizations. To deal with them I want to remove items from the list above according to the value in the column Type. For example, if the value in the column Type is center, then the word center should be deleted from the list and it will look like this ( c("hospital", "polyclinic", "dispencer")). After that I will just delete everything before the word from the list so that it will look like this:
Name | Type | Name after |
---|---|---|
cure center state hospital | hospital | state hospital |
state polyclinic cure center | center | cure center |
state hospital main dispancer | dispancer | main dispancer |
first hospital number one | hospital | first hospital number one |
The data to work with is:
Name <- c("cure center state hospital","state polyclinic cure center","state hospital main dispancer","first hospital number one",)
Type <- c("hospital", "center", "dispancer", "hospital")
Do you have any ideas?