Question: Could someone tell me how to pass the output of one CURL GET to another CURL POST? I mean something like this:

```
curl --header "Content-Type: application/json" --request POST --data "{\"specification\": curl --header "Content-Type: application/json" --request GET "https://user:pass@anotherhost"}" "https://user:pass@localhost"

```

Answer: 
We can use a group by operation in `dplyr` i.e. grouped by 'ID', extract the 'code' where the 'type' value is "large" (assuming there are no duplicate values for 'type' within each 'ID'

```
library(dplyr)
df <- df %>% 
   group_by(ID) %>%
   mutate(code2 = code[type == 'large']) %>%
   ungroup

```

-output

```
df
# A tibble: 7 x 4
  ID    type  code    code2  
  <chr> <chr> <chr>   <chr>  
1 A1    small B9      [0,20] 
2 A1    large [0,20]  [0,20] 
3 A2    small B9      [20,40]
4 A2    large [20,40] [20,40]
5 A3    large [0,20]  [0,20] 
6 A4    small B9      [40,60]
7 A4    large [40,60] [40,60]

```

---

If there are duplicates, use `match`, which will give the index of the first matching index

```
df <- df %>%
       group_by(ID) %>%
       mutate(code2 = code[match('large', type)]) %>%
       ungroup

```
A `data.table` option

```
> setDT(df)[, code2 := code[type == "large"], ID][]
   ID  type    code   code2
1: A1 small      B9  [0,20]
2: A1 large  [0,20]  [0,20]
3: A2 small      B9 [20,40]
4: A2 large [20,40] [20,40]
5: A3 large  [0,20]  [0,20]
6: A4 small      B9 [40,60]
7: A4 large [40,60] [40,60]

```