This vignette displays how to use nesting in tidyfst. It has referred to tidyrs vignette in https://tidyr.tidyverse.org/articles/nest.html. Now fist, we nest the “mtcars” data.frame by “cyl” column.

Now, we want to do a regression within the nested group “cyl”. We’ll use the famous lapply to complete this:

We could see that the model is stored in the column “model”. Now, we try to get the fitted value in the model.

We could find that the “model_predict” is a list of numeric vectors. Let’s try to unnest the target column “model_predict”.

This process would remove all the other list column automatically. For instance, in our case, the column “ndt” is removed.