[R] Add blank rows to a dataframe

Bert Jacobs bert.jacobs at figurestofacts.be
Sat Jun 8 13:09:49 CEST 2013


I have a vector that looks like this:
RowSel <-c(0,1,0,1,2,3,0,5,5)

Now I want to select rows from a specific dataframe DF based on that vector
like this:
SubDF <- DF[RowSel,]

So this works fine, but I was wondering how I could add blank rows add the
locations in the vector where there is a zero:
So the final dataframe should look like this:

[1] blank row
[2] row 1
[3] blank row
[4] row 1 
[5] row 2
[6] row 3
[7] blank row
[8] row 5
[9] row 5

Do I have to use a loop for this or does there exist a straight forward
function option.


More information about the R-help mailing list