Actually, I'm not sure I understood what you want. Is it something like this?
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(zeallot)
set.seed(seed = 37928)
dat <- tibble(tid = c(1, 1, 2, 2, 2, 3, 3, 3, 3),
count = c(2, 2, 3, 3, 3, 4, 4, 4, 4),
item = c(1, 2, 7, 9, 1, 12, 3, 2, 9),
name = c("rice", "beans", "meat", "lettuce", "rice", "soda", "water", "beans", "lettuce"))
dat %>%
group_by(tid) %>%
mutate(random_split_indices = sample(x = c(1, rep.int(x = 0,
times = (n() - 1))))) %>%
ungroup() %>%
group_split(random_split_indices,
keep = FALSE) %->% c(kept, left)
kept
#> # A tibble: 6 x 4
#> tid count item name
#> <dbl> <dbl> <dbl> <chr>
#> 1 1 2 1 rice
#> 2 2 3 7 meat
#> 3 2 3 1 rice
#> 4 3 4 12 soda
#> 5 3 4 3 water
#> 6 3 4 9 lettuce
left
#> # A tibble: 3 x 4
#> tid count item name
#> <dbl> <dbl> <dbl> <chr>
#> 1 1 2 2 beans
#> 2 2 3 9 lettuce
#> 3 3 4 2 beans
Created on 2019-08-21 by the reprex package (v0.3.0)
Or, like this?
dat %>%
group_by(tid) %>%
mutate(random_split_indices = sample(x = c(1, rep.int(x = 0,
times = (n() - 1))))) %>%
ungroup() %>%
group_nest(tid, count, random_split_indices,
.key = "item_and_name")