An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111226/7b0514cf/attachment.pl>
comparing fields within a record
5 messages · Eric Wolff, Jorge I Velez, David Winsemius
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111226/5f601442/attachment.pl>
On Dec 26, 2011, at 7:52 PM, Eric Wolff wrote:
Hi, I hope this isn't a really simple question, I've been struggling with it for a while. I'm looking for a way to get a function to go through a data frame line by line, compare fields, and produce a result, kind of a transform and an if statement combined (I tried to put them together and it didn't work). So, consider data Sales: House number Inspected Sold 1 9/2/2011 10/10/2011 2 9/4/2011 10/20/2011 3 10/31/2011 8/28/2011 4 8/3/2011 11/1/2011 I want to find all the records which were inspected after they were sold. Ideally, this code would create a fourth field that would be a logical. I tried Sales<-transform(Sales, Checked=if(Sales$Inspected <= Sales$Sold) "OK")
dat <- within(x, Checked <- as.Date(Inspected, format="%m/%d/%Y") < as.Date(Sold, format="%m/%d/%Y")) Note: it might have been easier if you had converted those string or factor variables into R Date variables. -- David Winsemius, MD West Hartford, CT
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111227/ddbb3952/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111227/7a10f0d9/attachment.pl>