Thanks for this! If i understand correctly, you're wanting to run your lagthemats function for each bit of data in your nested data frame that corresponds to each ID?
This should do the trick: mutate(nested_df, data_lag = map(data, lagthemats, 1))
When you use map() inside mutate() you can refer to variables in the data directly and don't need to use the $ selection syntax that you had originally.
A word of caution about lagthemats(), though, it looks like it's maybe calculating the lead of each row, not the lag (at least based on how I would define lead/lag), i.e. you're getting the next row each time, not the previous one:
> nested_df %>%
+ mutate(data_lag = map(data, lagthemats, 1)) %>%
+ unnest()
# A tibble: 9 x 7
# Groups: ID [3]
ID X1 X2 X3 X11 X21 X31
<dbl> <int> <int> <int> <int> <int> <int>
1 1 0 1 0 0 1 1
2 1 0 1 1 1 1 1
3 1 1 1 1 NA NA NA
4 2 0 0 0 0 0 0
5 2 0 0 0 0 1 1
6 2 0 1 1 NA NA NA
7 3 1 1 1 0 1 1
8 3 0 1 1 1 0 1
9 3 1 0 1 NA NA NA