# Remove elements from character vector in R

x<-c(21, 43, 56, 39, 45) # elements to be removed y<-c(43, 39, 45)   # Positions of the values of y in x idx = which(x %in% y) # Remove those values using their position and "-" operator x = x[-idx]   # Option 1 x = x[ - which(x %in% y)] # Option 2 x = x[! x %in% y]