[R] Is this an artifact of using "which"?

Tania Oh tania.oh at bnc.ox.ac.uk
Mon Apr 14 13:32:15 CEST 2008


Dear all,

I used "which" to obtain a subset of values from my data.frame.  
however, I find that there is a "trace" of the values I  have removed.  
Any suggestions would be greatly appreciate.

Below is my data:

d <- data.frame( val   = 1:10,
                 group = sample(LETTERS[1:5], 10, repl=TRUE) )

 >d
    val group
1    1     B
2    2     E
3    3     B
4    4     C
5    5     A
6    6     B
7    7     A
8    8     E
9    9     E
10  10     A

## selecting everything that is not group "A"
  d<-d[which(d$group !="A"),]

 > d
   val group
1   1     B
2   2     E
3   3     B
4   4     C
6   6     B
8   8     E
9   9     E

 > levels(d$group)
[1] "A" "B" "C" "E"

## why is group A still reflected here?

Many thanks in advance,
tania

D.phil student
Department of Physiology, Anatomy and Genetics
Oxford University



More information about the R-help mailing list