create new column with values in a row are right of a specific text

Hello

I have a large dataframe and I want to create a new column with gives me the value of cell on the right side of a cell that contains a specific text.

I want to fill a new last column (I will name the column Caffeine) with the values that are written on the right side of the word "caffeine" anywhere in the row. So for example if Caffeine is written in am row in column 4, it will give me the value of column 5 in the same row and if it is written in column 7 it will give me the answer in column 8. If Caffeine is not written in the this row, it will give me NA
The problem is that caffeine can be written in various places (here in columns concurrent medication 1 AND 2). I have tried it with index and math, but I cannot get it to work.

does anyone know a solution for this?

Please post a small sample of your data. You can do this by posting the output of a call like

dput(head(DF, 10))

where you should replace DF with the name of your data frame. That will provide the first 10 rows of your data. Paste the output between two lines that have three back ticks, like this
```
pasted output goes here
```

This topic was automatically closed 21 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.