Q:

Subset and filter not giving proper answer

I have following dataset and used subset and filter to segment the data:
KL <- read.table(text = "
ID  C1
A   597.69
B   239.64
C   601.3
D   4052.6
E   73.73
F   74.06
G   124
H   0
I   0
J   0
K   0
L   122.45
M   152.88
N   123.32
O   354.12",
stringsAsFactors = FALSE,
header = TRUE)

str(KL)
Classes ‘data.table’ and 'data.frame':  15 obs. of  2 variables:
 $ ID: chr  "A" "B" "C" "D" ...
 $ C1: num  597.7 239.6 601.3 4052.6 73.7 ...

When I applied subset conditions
cl4  = subset(KL, C1 > "300.00")

Output is:
ID C1
A  597.69
C  601.30
D  4052.60
E  73.73
F  74.06
O  354.12

Why is it still showing number less than 300?
I have tried filter also but the output is same.

A:

Since your column C1 is numeric, you should not use quotes. Try this:
 subset(KL, C1 > 300)

   ID      C1
1   A  597.69
3   C  601.30
4   D 4052.60
15  O  354.12

But note that you should use caution with subset() - this will not always do what you think it does.
It's better to use [ for subsetting:
KL[KL$C1 > 300, ]
   ID      C1
1   A  597.69
3   C  601.30
4   D 4052.60
15  O  354.12

