Question: I want to convert a certain list of strings into separated lists inside another list, which will contain strings and floats.
I've tried to use the `append` method to get the result, but I'm having trouble on making the nested list. Is there a way to get only the last line of my `output` as the result? This is my code:

```
def func(L):
    n = []
    lists = [i.split(',') for i in L]
    for xlist in lists:
        xlist[1:] = [float(item) for item in xlist[1:]]
        n.append(xlist)
        print(n)

if __name__ == '__main__':
    func(['PersonX, 10, 92, 70', 'PersonY, 60, 70', 'PersonZ, 98.5, 1100, 95.5, 38'])

OUTPUT: [['PersonX', 10.0, 92.0, 70.0]]
        [['PersonX', 10.0, 92.0, 70.0], ['PersonY', 60.0, 70.0]]
        [['PersonX', 10.0, 92.0, 70.0], ['PersonY', 60.0, 70.0], ['PersonZ', 98.5, 1100.0, 95.5, 38.0]]

EXPECTED OUTPUT: [['PersonX', 10.0, 92.0, 70.0], ['PersonY', 60.0, 70.0], ['PersonZ', 98.5, 1100.0, 95.5, 38.0]]

```

Thanks in advance for any help.

Answer: 
I actually recently made a little helper function for exactly this. The idea
is to use `group_modify()` to take the group data, and
`bind_rows()` the summary statistics calculated with `summarise()`.

This is what it looks like in code:

```r
add_summary_rows <- function(.data, ...) {
  group_modify(.data, function(x, y) bind_rows(x, summarise(x, ...)))
}

```

And here’s how that would work with your data:

```r
library(dplyr, warn.conflicts = FALSE)

df <- data.frame(
  test_id = c(1, 1, 1, 1, 1, 1, 1, 1),
  test_nr = c(1, 1, 1, 1, 2, 2, 2, 2),
  region = c("A", "B", "C", "D", "A", "B", "C", "D"),
  test_value = c(3, 1, 1, 2, 4, 2, 4, 1)
)

df %>% 
  group_by(test_id, test_nr) %>% 
  add_summary_rows(
    region = "MEAN",
    test_value = mean(test_value)
  )
#> # A tibble: 10 x 4
#> # Groups:   test_id, test_nr [2]
#>    test_id test_nr region test_value
#>      <dbl>   <dbl> <chr>       <dbl>
#>  1       1       1 A            3   
#>  2       1       1 B            1   
#>  3       1       1 C            1   
#>  4       1       1 D            2   
#>  5       1       1 MEAN         1.75
#>  6       1       2 A            4   
#>  7       1       2 B            2   
#>  8       1       2 C            4   
#>  9       1       2 D            1   
#> 10       1       2 MEAN         2.75

```
You can combine your two approaches:

```
    df %>%
      split(~test_nr) %>%
      map_dfr(~ .x %>% 
                add_row(test_id = .$test_id[1], 
                        test_nr = .$test_nr[1], 
                        region = "mean",
                        test_value = mean(.$test_value)))  

```