How to delete observations that have have specific value of one variable?

My original data set is

> head(vowel.train, 22)
   row.names  y    x.1   x.2    x.3   x.4    x.5   x.6    x.7    x.8    x.9   x.10
1          1  1 -3.639 0.418 -0.670 1.779 -0.168 1.627 -0.388  0.529 -0.874 -0.814
2          2  2 -3.327 0.496 -0.694 1.365 -0.265 1.933 -0.363  0.510 -0.621 -0.488
3          3  3 -2.120 0.894 -1.576 0.147 -0.707 1.559 -0.579  0.676 -0.809 -0.049
4          4  4 -2.287 1.809 -1.498 1.012 -1.053 1.060 -0.567  0.235 -0.091 -0.795
5          5  5 -2.598 1.938 -0.846 1.062 -1.633 0.764  0.394 -0.150  0.277 -0.396
6          6  6 -2.852 1.914 -0.755 0.825 -1.588 0.855  0.217 -0.246  0.238 -0.365
7          7  7 -3.482 2.524 -0.433 1.048 -1.995 0.902  0.322  0.450  0.377 -0.366
8          8  8 -3.941 2.305  0.124 1.771 -1.815 0.593 -0.435  0.992  0.575 -0.301
9          9  9 -3.860 2.116 -0.939 0.688 -0.675 1.679 -0.512  0.928 -0.167 -0.434
10        10 10 -3.648 1.812 -1.378 1.578  0.065 1.577 -0.466  0.702  0.060 -0.836
11        11 11 -3.032 1.739 -1.141 0.737 -0.834 1.386 -0.575  0.679 -0.018 -0.823
12        12  1 -3.653 0.373 -0.600 1.705 -0.222 1.765 -0.353  0.537 -0.797 -0.813
13        13  2 -3.237 0.436 -0.860 1.363 -0.251 1.915 -0.395  0.751 -0.774 -0.327
14        14  3 -2.135 0.954 -1.632 0.121 -0.704 1.600 -0.628  0.713 -0.903 -0.027
15        15  4 -2.304 1.784 -1.506 0.981 -0.961 0.806 -0.294 -0.002  0.119 -0.760
16        16  5 -2.540 2.144 -1.024 0.933 -1.567 1.024  0.188 -0.047  0.309 -0.633
17        17  6 -2.826 2.003 -0.738 0.801 -1.669 0.939  0.245 -0.257  0.256 -0.458
18        18  7 -3.582 2.374 -0.358 1.162 -1.953 0.621  0.339  0.355  0.415 -0.259
19        19  8 -3.951 2.250  0.127 1.772 -1.906 0.567 -0.432  1.045  0.598 -0.293
20        20  9 -3.783 1.974 -1.200 0.606 -0.650 1.504 -0.134  0.528  0.392 -0.580
21        21 10 -3.673 1.811 -1.405 1.621  0.044 1.572 -0.453  0.745 -0.066 -0.733
22        22 11 -2.946 1.649 -1.167 0.788 -0.909 1.300 -0.562  0.902 -0.070 -0.842

Notice that y variable is my group_id. The id repeats from 1 to 11. And I have hundreds of such observations. Now I want to delete all the observations who have id 5, 8, 9, 10. i.e., I want to from a new data frame that only contains y=1,2,3,4,6,7. How to do?

Perhaps

library(tidyverse)
new.vowel.train <- vowel.train %>% filter(y %in% c(1,2,3,4,5,6,7))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.