Deleting every n-th row in a dataframe

Yktula picture Yktula · Oct 30, 2011 · Viewed 25.5k times · Source

How can I delete every n-th row from a dataframe in R?

Answer

Tyler Rinker picture Tyler Rinker · Oct 30, 2011

You could create a function as follows

Nth.delete<-function(dataframe, n)dataframe[-(seq(n,to=nrow(dataframe),by=n)),]

Let's test it out

DF<-data.frame(A=1:15, B=rnorm(15), C=sample(LETTERS,15))
Nth.delete(DF, 3)