Created
February 16, 2013 19:10
-
-
Save nassimhaddad/4968264 to your computer and use it in GitHub Desktop.
insert a row to a data frame at a wanted position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert_row <- function(existingDF, newrow, r){ | |
r <- as.numeric(r) | |
if (length(newrow) != ncol(existingDF)){ | |
stop("Length of row doesn't match.") | |
} | |
if (r == 1){ | |
existingDF <- rbind(newrow,existingDF) | |
} else{ | |
existingDF <- rbind(existingDF[1:(r-1),],newrow,existingDF[-(1:(r-1)),]) | |
} | |
return(existingDF) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment