Let's say in my data (e.g. iris), I want to group only one variable-Sepal.Length by Species and add two rows- one at the top (name of the group) "setosa", followed by observations then after the observations of setosa have ended, a row saying "END", followed by two blank rows, after which new group name "versicolor" starts with its observations with an "END" row etc etc. My real data has over 200 groups and observations are characters.
So far, I have achieved this with dplyr
iris %>%
group_by(Species) %>%
select(Sepal.Length) %>%
add_row(.before=0,.after=0)
Needless to say, my add_row is not working, I have also tried using bind_rows and mutate. Any suggestions would be greatly appreciated, I want my output to look like, which I will export as txt file.
setosa
4.1
5.1
.
.
END
<empty row1>
<empty row2>
versicolor
5.1
6.1
.
.
END
<empty row1>
<empty row2>