Compare two data.frames to find the rows in data.frame 1 that are not present in data.frame 2

sqldf provides a nice solution a1 <- data.frame(a = 1:5, b=letters[1:5]) a2 <- data.frame(a = 1:3, b=letters[1:3]) require(sqldf) a1NotIna2 <- sqldf(‘SELECT * FROM a1 EXCEPT SELECT * FROM a2’) And the rows which are in both data frames: a1Ina2 <- sqldf(‘SELECT * FROM a1 INTERSECT SELECT * FROM a2’) The new version of dplyr has … Read more

Why is one string greater than the other when comparing strings in JavaScript?

Because, as in many programming languages, strings are compared lexicographically. You can think of this as a fancier version of alphabetical ordering, the difference being that alphabetic ordering only covers the 26 characters a through z. This answer is in response to a java question, but the logic is exactly the same. Another good one: … Read more

How can I compare two dates in PHP?

If all your dates are posterior to the 1st of January of 1970, you could use something like: $today = date(“Y-m-d”); $expire = $row->expireDate; //from database $today_time = strtotime($today); $expire_time = strtotime($expire); if ($expire_time < $today_time) { /* do Something */ } If you are using PHP 5 >= 5.2.0, you could use the DateTime … Read more