0

I would like to filter my data frame based on integer values from the first column v :

      v P_el
1   2.5    0
2   3.0   78
3   3.5  172
4   4.0  287
5   4.5  426
6   5.0  601
7   5.5  814
8   6.0 1069
9   6.5 1367
10  7.0 1717
11  7.5 2110
12  8.0 2546
13  8.5 3002
14  9.0 3427
15  9.5 3751
16 10.0 3922

The output should look like this :

    v P_el
2   3   78
4   4  287
6   5  601
8   6 1069
10  7 1717
12  8 2546
14  9 3427
16 10 3922
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Haribo
  • 2,071
  • 17
  • 37

2 Answers2

3

We can check if the values divided by one are with a remainder of 0.

dat[dat$v %% 1 == 0, ]
    v P_el
2   3   78
4   4  287
6   5  601
8   6 1069
10  7 1717
12  8 2546
14  9 3427
16 10 3922

DATA

dat <- read.table(text = "      v P_el
1   2.5    0
                  2   3.0   78
                  3   3.5  172
                  4   4.0  287
                  5   4.5  426
                  6   5.0  601
                  7   5.5  814
                  8   6.0 1069
                  9   6.5 1367
                  10  7.0 1717
                  11  7.5 2110
                  12  8.0 2546
                  13  8.5 3002
                  14  9.0 3427
                  15  9.5 3751
                  16 10.0 3922",
                  header = TRUE)
www
  • 38,575
  • 12
  • 48
  • 84
0

You can use seq( ) function if you have an idea of sequence in column v

  dat
  #       v P_el
  # 1   2.5    0
  # 2   3.0   78
  # 3   3.5  172
  # 4   4.0  287
  # 5   4.5  426
  # 6   5.0  601
  # 7   5.5  814
  # 8   6.0 1069
  # 9   6.5 1367
  # 10  7.0 1717
  # 11  7.5 2110
  # 12  8.0 2546
  # 13  8.5 3002
  # 14  9.0 3427
  # 15  9.5 3751
  # 16 10.0 3922


  dat[seq(2,16,by = 2),]
  #     v P_el
  # 2   3   78
  # 4   4  287
  # 6   5  601
  # 8   6 1069
  # 10  7 1717
  # 12  8 2546
  # 14  9 3427
  # 16 10 3922
Sowmya S. Manian
  • 3,723
  • 3
  • 18
  • 30