Question: Here is my original df: 

```
my_df_1 <- data.frame(col_1 = c(rep('a',5), rep('b',5), rep('c', 5)),
                    col_2 = c(rep('x',3), rep('y', 9), rep('x', 3)))

```

I would like to group by `col_1` and return 1 if `col_2` for given group contains `x`, and 0 if not. 

Here is how final result is supposed to look:

```
my_df_2 <- data.frame(col_1 = c(rep('a',5), rep('b',5), rep('c', 5)),
                col_2 = c(rep('x',3), rep('y', 9), rep('x', 3)), 
                col_3 = c(rep(1,5), rep(0,5), rep(1, 5)))

```

I would prefer to get it done with `dplyr`, if possible. This is kind of `count if` predicate, but cannot find it.

Answer: 
What about this?

```
do <- as.data.frame(do.call(rbind, lapply(my.stuff, as.vector)))
do <- cbind(my.var=rownames(do), do)
do[do == "NULL"] <- NA

```

***Result***

```
> do
   my.var my.col1 my.col2 my.col3 my.col4
AA     AA       1       4      NA      NA
BB     BB      NA      NA      NA      NA
CC     CC      13       8       2      10
DD     DD      NA      NA      -5       7

```

### *Edit:*

If we don't want lists as column objects as @akrun reasonably suggests, we could do it this way:

```
u <- as.character(unlist(my.stuff, recursive=FALSE))
u[u == "NULL"] <- NA
do <- matrix(as.integer(u), nrow=4, byrow=TRUE, 
             dimnames=list(NULL, names(my.stuff[[1]])))
do <- data.frame(my.var=names(my.stuff), do, stringsAsFactors=FALSE)

```

***Test:***

```none
> all.equal(str(do), str(desired.object))
'data.frame':   4 obs. of  5 variables:
 $ my.var : chr  "AA" "BB" "CC" "DD"
 $ my.col1: int  1 NA 13 NA
 $ my.col2: int  4 NA 8 NA
 $ my.col3: int  NA NA 2 -5
 $ my.col4: int  NA NA 10 7
'data.frame':   4 obs. of  5 variables:
 $ my.var : chr  "AA" "BB" "CC" "DD"
 $ my.col1: int  1 NA 13 NA
 $ my.col2: int  4 NA 8 NA
 $ my.col3: int  NA NA 2 -5
 $ my.col4: int  NA NA 10 7
[1] TRUE

```
We can use a recursive `map`

```
library(tidyverse)
map_df(my.stuff, ~ map_df(.x,  ~ 
                      replace(.x, is.null(.x), NA)), .id = "my.var")  
# A tibble: 4 x 5
#  my.var my.col1 my.col2 my.col3 my.col4
#  <chr>    <dbl>   <dbl>   <dbl>   <dbl>
#1 AA           1       4      NA      NA
#2 BB          NA      NA      NA      NA
#3 CC          13       8       2      10
#4 DD          NA      NA      -5       7

```