Deleting values in a vector

Hi, I am new to R and in need of some assistance.

I would like to delete some values from a vector but struggling to do this.

I have tried boolean operators, filter() and a few other combinations from things I've read online but nothing has worked so far.

Any help appreciated

I want to delete the 7, 8, and 9 and all their observations from my data set.

#If I want to remove 123456789:

df <- data.frame(first = c(1, 1, 1,1, 1, 1),
second = c(1,1,1,1,1,1),
thirth = c(1,1,123456789,123456789, 1, 1),
fourth = c(1,1,1,1,1, 123456789))
df
df$thirth[(3:4)] <- 0
df$fourth[6] <- 0
df

Without a reprex (see the FAQ: How to do a minimal reproducible example reprex for beginners), it's difficult to infer the structure of the w2q7.1 object, so I have to use synthetic data.

set.seed(42)
v1 <- sample(1:100,10)
v2 <- sample(LETTERS,10)
d <- data.frame(v1 = v1, v2 = v2)
d
#>     v1 v2
#> 1   49  E
#> 2   65  N
#> 3   25  T
#> 4   74  R
#> 5   18  O
#> 6  100  C
#> 7   47  I
#> 8   24  D
#> 9   71  Z
#> 10  89  M
# subset data frame d to include only those rows whose first
# column does not include the values 49, 25 or 18
d[which(!d$v1 %in% c(49,25,18)),]
#>     v1 v2
#> 2   65  N
#> 4   74  R
#> 6  100  C
#> 7   47  I
#> 8   24  D
#> 9   71  Z
#> 10  89  M

Thanks for replying. When I get to the datapasta section of the reprex it says this:

Is this helpful in place of the reprex?

Reading back, not sure i have been 100% clear.

So basically I want to delete the columns 'Mssing', 'Do not understand the question, 'Cant choose', and 'Decline to answer' and all the responses to those options.

Working with the table object makes things much more difficult than they need be. What does the WAVE_4_SPSS object look like?

Why does table make things more difficult?

I just went through the data in SPSS and manually deleted all the value so no longer an issue

I would like you to provide a reprex of your problem. It will b easier to help.

This topic was automatically closed 21 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.