I want to build post-hoc testing for log-rank test, that compare individual groups to each other:

```
library(survival)
survdiff(DV ~ IV, data=mydf)

```

Is there any way to do something like this (e.g. to compare group 2 with group 7):

```
survdiff(DV ~ I(if(as.numeric(IV) == 2) {1} else {if(as.numeric(IV) == 7) {2} else {NA}} ), data=mydf )

```

---

I know that I can filter out not needed rows from `mydf` and the `Surv` object `DV`

```
df2vs7<-mydf[as.numeric(mydf$IV)==2 | as.numeric(mydf$IV)==7,]
DV2vs7<-DV[as.numeric(mydf$IV)==2 | as.numeric(mydf$IV)==7,]

```

But I think it is highly inefficient; the computer would need to store each separate data objects for each combination of compared groups.