2

I have a data frame named df:

number          value
1                  5
2                  5
3                  5
4                  6
5                  6
6                  6
7                  6
8                  7 
9                  7
10                7
11                7
12                7
13                8  
14                9 
15                9

I want to remove specific rows in case of a min and max level. I tried separate this:

df[df$value>5 , ]

and after that this:

df[df$value>8 , ]

After I tried this:

df[df$value>5 & df$value>8, ]

but it execute online the df$value>8

and another problem I observed is that when I type

 df[df$value>5, ]

it eliminate the value however when I type df it contains the values I tried to remove before. What could be wrong and I don’t take a clear data frames without the removed values?

An example of the output data:

 number          value
 4                  6
 5                  6
 6                  6
 7                  6
 8                  7 
 9                  7
 10                7
 11                7
 12                7

1 Answers1

3

If you want remove lines with level lower than min and higher than max, try this:

df[df$value<5 | df$value>8, ]

Edit

Look right code:

df <- df[df$value>5 & df$value<8,]

Its work for me.

Eugene
  • 1,899
  • 1
  • 13
  • 10
  • The problem remains the same. Whatever values of the first <5 removed but whatever values >8 remain in the frame... –  May 07 '13 at 13:50
  • Your right, fir code not work. see fixed example, it work for me. – Eugene May 07 '13 at 15:00