Delete nth row in R data frame?

I have a data frame containing 1 minute measurements for things like humidity, soil temperature, air temperature, radiation, etc. (14 columns and about 35,000 rows).

I would like to delete every nth row so that the sampling interval is longer, say 3 minutes, etc., this also speeds up the process when I combine all the frames together to create a data frame for the year.

Is there anyway that R automatically deletes every nth row? without indicating the number of each line? This is a sample data frame.

V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 1 2012-11-01 00:00:00 24587 13.16 9.260 0.028 0.016 0.013 0.009 8.200 7.643 8.370 67.66 13.930 14.910 2 2012-11-01 00:01:00 24588 13.16 9.250 0.024 0.011 0.009 0.008 8.220 7.725 8.380 67.24 13.930 14.910 3 2012-11-01 00:02:00 24589 13.15 9.250 0.025 0.009 0.011 0.004 8.240 7.741 8.390 67.12 13.930 14.910 4 2012-11-01 00:03:00 24590 13.15 9.240 0.022 0.007 0.007 0.011 8.210 7.695 8.390 67.48 13.930 14.910 5 2012-11-01 00:04:00 24591 13.16 9.230 0.025 0.011 0.010 0.006 8.190 7.689 8.380 67.82 13.930 14.910 6 2012-11-01 00:05:00 24592 13.16 9.230 0.024 0.009 0.010 0.012 8.170 7.672 8.360 68.03 13.930 14.910 7 2012-11-01 00:06:00 24593 13.16 9.220 0.029 0.011 0.008 0.011 8.170 7.685 8.350 67.71 13.930 14.910 

Thanks!

+4
source share
1 answer

There are many different ways to do this, simple:

 # make an index eg. every 3th ind <- seq(1, nrow(df), by=3) # make subset --> this would choose every `ind` row df[ind, ] # --> this would exclude ale `ind` row df[-ind, ] 

Hth

+5
source

Source: https://habr.com/ru/post/1497679/


All Articles