-8

I am trying to remove couple elements from a dataset. It has A,B,C,1,2,3,4,5 as its contents:

 >dataset
    [1] A 4 3 C 3 3 3 C 3 B 3 4 3 3 3 B 3 3 5 3 3 4 A 3 3 5 3 3 4 3 2 3 C 6 A 3 3
    [38] 3 A 3 3 A 3 3 3 3 3 A 3 C B 3 B 3 A 3 1 8 1 1 C 1 1 3 3 3 3 B 3 A A 3 5 3

I want to remove all "A"s and "B"s from the dataset. The expected dataset should only have 1,2,3,4,5,C as its elements.

I have tried with following codes but could not succeed:

>rm(dataset$"B")    # to remove "B"s


> x.sub <- subset(dataset, "B" > 1) #to remove Bs appearing more than once

Do you know how can I remove them?

bapors
  • 887
  • 9
  • 26
  • 1
    You should include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data in a copy/paste-able format. Also give the desired ouput for the sample input. Maybe start with [an introduction to R](https://cran.r-project.org/doc/manuals/r-release/R-intro.html) because you seem to be missing some of the basics. – MrFlick Jun 14 '17 at 18:03

1 Answers1

1
dataset <- dataset[!(dataset %in% c('A','B'))]
Mouad_Seridi
  • 2,666
  • 15
  • 27