I am trying to use values_fn argument in pivot_wider function.
Initially I end up with list column, and I want to use length function (in values_fn) for each cell to get the length
My list columns contain NULL. It seems, length function does not work with list element NULL, it gives NA. But, length(NULL) = 0. So, I am expecting 0 instead of NA.
Thank you very much for the reply. It definitely solves the problem using values_fill. But, I was trying to understand how values_fn works and later use it for other purpose.
When I try to use values_fn = length in pivot_wider, technically it is not working correctly for each cell (as it's documentation says " Optionally, a function applied to the value in each cell in the output"). NULL is nothing special and length(NULL)=0. I was expecting output as the output of map_dbl as above. The other thing I have noticed problematic, other argument of values_fn (say na.rm of mean) can not be passed to ... (dot dot dot of pivot_wider). Thanks