Background:
I have a little dataframe
composed of percentage estimates across two characteristics
. One is "political party", the other is "sex". As it stands, these specific names are unmentioned in the df
even if the categories that comprise them are. Here it is:
d <- data.frame(characteristic = c("Republican","Democrat","Male","Female"),
percent = c(45, 55, 70, 30),
stringsAsFactors=FALSE)
For those without R
available to them at the moment, here's what that looks like:
The Problem:
As the result of data analysis, this df
is perfectly adequate. But because I want to export it is a .csv file and insert it into a report I'm writing, I'd like to make some aesthetic modifications in order to make that integration as smooth as possible. In particular, I'd like to insert 2 blank rows to act as subheadings. In other words, I'm looking to do something like this:
What I've tried:
I feel I'm quite close, because I can get the new rows in using these two lines of code:
d[nrow(d) + 1,] = c("Party","")
d[nrow(d) + 1,] = c("Sex","")
But that only appends them to the bottom of the dataset and I'm not sure how to move them into the desired positions, or if there a more efficient way to do this.
Thanks for any help!