Select every nth row from dataframe

后端 未结 3 818
灰色年华
灰色年华 2020-11-28 09:41

I have a data table and want to extract every fifth row from it to create a new table. Is there a command to achieve this?

Here is an sample of my data:



        
3条回答
  •  我在风中等你
    2020-11-28 10:43

    If you want to extract 5,10...

    newdf <- df[c(rep(FALSE,4),TRUE), ]
    

    If 1,6,11,

    newdf <- df[c(TRUE,rep(FALSE,4)), ]
    

提交回复
热议问题