<div>
<div>Matthew,</div><div><br></div><div>Regarding your suggestion of changes regarding Frank's post here: <a href="http://stackoverflow.com/a/17008872/559784" style="color: rgb(0, 106, 227); ">http://stackoverflow.com/a/17008872/559784</a> I find it a bit more confusing and frankly not like sql.</div><div><br></div><div>You wrote: <span style="line-height: 18px; text-align: left; ">"If I haven't understood correctly feel free to correct, otherwise the change will get made eventually. It will need to be done in a way that considers compound expressions; e.g., </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">DT[colA=="foo" & colB!="bar"]</code><span style="line-height: 18px; text-align: left; "> should exclude rows with </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">NA</code><span style="line-height: 18px; text-align: left; "> in </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">colA</code><span style="line-height: 18px; text-align: left; "> but include rows where </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">colA</code><span style="line-height: 18px; text-align: left; "> is non-</span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">NA</code><span style="line-height: 18px; text-align: left; "> but </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">colB</code><span style="line-height: 18px; text-align: left; "> is </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">NA</code><span style="line-height: 18px; text-align: left; ">. Similarly, </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">DT[colA!=colB]</code><span style="line-height: 18px; text-align: left; "> should include rows where either colA or colB is </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">NA</code><span style="line-height: 18px; text-align: left; "> but not both. And perhaps </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">DT[colA==colB]</code><span style="line-height: 18px; text-align: left; "> should include rows where both</span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">colA</code><span style="line-height: 18px; text-align: left; "> and </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">colB</code><span style="line-height: 18px; text-align: left; "> are </span><code style="margin: 0px; padding: 1px 5px; border: 0px; vertical-align: baseline; background-color: rgb(238, 238, 238); line-height: 18px; text-align: left; ">NA</code><span style="line-height: 18px; text-align: left; "> (which it doesn't currently, I believe)."</span></div><div><span style="line-height: 18px; text-align: left; "><br></span></div><div style="text-align: left; ">Even though sql (ex: sqldf) has a different way of handling NAs when compared to data.frame, it doesn't seem to find NA == NA. That is,</div><div style="text-align: left; "><br></div><div style="text-align: left; ">df <- data.frame(x = c(1:3,NA), y = c(NA,4:5,NA))</div><div style="text-align: left; ">require(sqldf)</div><div style="text-align: left; "><br></div><div style="text-align: left; ">sqldf("select * from df where x == y")</div><div style="text-align: left; "># returns empty data.frame</div><div><br></div><div>sqldf("select * from df where x != y")</div><div><div> x y</div><div>1 2 4</div><div>2 3 5</div></div><div><br></div><div><div>That is, at least in sqldf package, NA is not == NA and NA is not != NA which is very much in coherence with R's default NA == NA and NA != NA (both giving NA). But I don't think they it's considered FALSE here. It just acts like the "subset" function where all entries that were evaluated to NAs are simply dropped. But with data.table philosophy NA != NA should be evaluated to TRUE, which I don't think (from what I meagrely understand from sql) is what sql does. Please correct me if I've got it wrong.</div><div><br></div><div>I think it is clearer and simpler if "NAs are just dropped" after evaluating logical expressions. It would be also easy to document this and easier to grasp, imho. This would also explain Frank's post for NA rows being removed. </div><div><br></div><div>And probably if there is more consensus an option for "na.rm = TRUE/FALSE" could be added?</div><div><br></div><div>Arun</div></div>
</div>
<div><div><br></div></div>