Search code examples
rsequencedataframerows

Deleting every n-th row in a dataframe


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


Solution

  • 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)