Q:

Trying to replace a set of numbers with zero in a dataframe

I have a dataframe with three columns and a lot of rows. One of the columns includes numbers like 80803 and 9995. I want to replace the specific numbers 80803 and 9995 in this column with 0.
Suppose my dataframe is called df.
I have tried to use the gsub function like gsub(80803,0,df).
But a error shows up which states pattern has length > 1 and only the first element will be used. 
This is an example of what my df looks like. Just with more rows.
a <- c(85.42, 80.80, 78.56 , 70.40)
b <- c(110, 80803, 9995, 50)
c <- c(3, 4 , 7, 5)
df <- data.frame(a, b, c)
df
      a     b c
1 85.42   110 3
2 80.80 80803 4
3 78.56  9995 7
4 70.40    50 5

This is what i want my df to look like.
df
      a     b c
1 85.42   110 3
2 80.80     0 4
3 78.56     0 7
4 70.40    50 5

A:

You can solve this issue in base R.
 df$b[df$b == 80803|df$b == 9995] <- 0

A:

We can create a logical vector with %in% and replace those values by assigning to 0
df$b[df$b %in% c(80803, 9995)] <- 0
df
#      a   b c
#1 85.42 110 3
#2 80.80   0 4
#3 78.56   0 7
#4 70.40  50 5

NOTE: This is done in base R only
NOTE2: This can also take any length of vector and wouldn't have an issue if there are NA elements

