Return a list in dplyr mutate()

后端 未结 3 1106
小鲜肉
小鲜肉 2020-12-17 16:03

I have a function in my real-world problem that returns a list. Is there any way to use this with the dplyr mutate()? This toy example doesn\'t work -:

it =          


        
3条回答
  •  感动是毒
    2020-12-17 16:31

    The mutate() function is designed to add new columns to the existing data frame. A data frame is a list of vectors of the same length. Thus, you cant add a list as a new column, because a list is not a vector.

    You can rewrite your function as two functions, each of which return a vector. Then apply each of these separately using mutate() and it should work.

提交回复
热议问题