Question: How can I extract the T3 Period, Year and maximum value?

*file.json*

```
[
{"Fecha":"2022-08-01T00:00:00.000+02:00", "T3_TipoDato":"Avance", "T3_Periodo":"M08", "Anyo":2022, "value":10.4},
{"Fecha":"2022-07-01T00:00:00.000+02:00", "T3_TipoDato":"Definitivo", "T3_Periodo":"M07", "Anyo":2022, "value":10.8},
{"Fecha":"2022-06-01T00:00:00.000+02:00", "T3_TipoDato":"Definitivo", "T3_Periodo":"M06", "Anyo":2022, "value":10.2}
]

```

My code:

```
import json

with open("file.json") as f: 
    distros_dict = json.load(f)

print (distros_dict)   

```

Answer: 
Base R way to do this:

`apply(df, 2, function(x) { x[ is.na(x) ] <- 'NULL'; x})`

Note that you can't really insert `NULL` as it has length 0, you can insert: `''` or `NA`
Here are two approaches. One assuming you want 0 in numeric columns and "unknown" in character, and one assuming you want 'NULL' independent of column type.

Approach 1:

```r
library(tidyr); library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"))
df %>% 
    mutate(
        across(where(is.numeric), replace_na, 0),
        across(where(is.character), replace_na, "unknown")
    )
#> # A tibble: 3 × 2
#>       x y      
#>   <dbl> <chr>  
#> 1     1 a      
#> 2     2 unknown
#> 3     0 b

```

Created on 2022-11-10 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)

Approach 2:

```r
library(tidyr); library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = c(1, 2, NA), y = c("a", NA, "b"))
df %>% 
    mutate(
        across(everything(), ~ if(anyNA(.)) replace_na(as.character(.), 'NULL'))
    )
#> # A tibble: 3 × 2
#>   x     y    
#>   <chr> <chr>
#> 1 1     a    
#> 2 2     NULL 
#> 3 NULL  b

```

Created on 2022-11-10 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)