How does one stop using rowwise in dplyr?

后端 未结 3 444
你的背包
你的背包 2020-12-13 08:33

So, if one wishes to apply an operation row by row in dplyr, one can use the rowwise function, for example: Applying a function to every row of a table using dp

3条回答
  •  遥遥无期
    2020-12-13 08:56

    You can use as.data.frame(), like below

    > data.frame(a=1:4) %>% rowwise() %>% group_by(a)
    # A tibble: 4 x 1
    # Groups:   a [4]
          a
    * 
    1     1
    2     2
    3     3
    4     4
    Warning message:
    Grouping rowwise data frame strips rowwise nature 
    
    > data.frame(a=1:4) %>% rowwise() %>% as.data.frame() %>% group_by(a)
    # A tibble: 4 x 1
    # Groups:   a [4]
          a
    * 
    1     1
    2     2
    3     3
    4     4
    

提交回复
热议问题