Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 445

Add row in each group using dplyr and add_row()

$
0
0

If I add a new row to the iris dataset with:

iris <- as_tibble(iris)> iris %>%     add_row(.before=0)# A tibble: 151 × 5    Sepal.Length Sepal.Width Petal.Length Petal.Width Species<dbl>       <dbl>        <dbl>       <dbl>   <chr>1            NA          NA           NA          NA    <NA> <--- Good!2           5.1         3.5          1.4         0.2  setosa3           4.9         3.0          1.4         0.2  setosa

It works. So, why can't I add a new row on top of each "subset" with:

iris %>%  group_by(Species) %>%  add_row(.before=0)Error: is.data.frame(df) is not TRUE

Viewing all articles
Browse latest Browse all 445

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>