How to complete missing factor levels in data frame?

后端 未结 1 1836
无人共我
无人共我 2020-11-30 11:39

Lets pretend I have something like this:

df <- data.frame(
      PERSON = c("Peter", "Peter", "Marcel" , "Lisa", &q         


        
相关标签:
1条回答
  • 2020-11-30 12:36

    The complete takes the first argument as 'data', followed by the columns to expand. By default, the fill is NA, but we can change it to 0 by specifying it in a list.

    complete(df, PERSON, FRUIT, fill = list(A=0, B = 0))
    
    0 讨论(0)
提交回复
热议问题