Question: See the following example:

```none
$ lua
Lua 5.4.4  Copyright (C) 1994-2022 Lua.org, PUC-Rio
> local a = 123
> print(a)
nil

```

This works as expected:

```none
> local a = 123; print(a)
123

```

How should I understand the behavior compared to the [doc](https://www.lua.org/manual/5.4/manual.html#3.5)?

> 
> The scope of a local variable begins at the first statement after its declaration and lasts until the last non-void statement of the innermost block that includes the declaration.
> 
> 
>

Answer: 
Wrapping the which inside of `lapply` will solve this problem:

```
lapply(mylist[,2], FUN = function(i) i[which(i$x == "c"),])

```

> 
> 
> ```
> $mylist
>   x y
> 3 c 3
> 
> $list2
>   x y
> 3 c 6
> 
> $list3
>   x y
> 3 c 9
> 
> ```
> 
>
Using `tidyverse`, we can loop over the `list` with `map` and use `if_any` to `filter`

```
library(dplyr)
library(purrr)
map(mylist[,2], ~ .x %>%
    filter(if_any(everything(), ~ .x == "c")))

```

-output

```
$mylist
  x y
1 c 3

$list2
  x y
1 c 6

$list3
  x y
1 c 9

```