Dear Kevin,

Assuming that closure and referral are two columns in your df and you have  
already converted them to date columns.

The following should work:

df$Dec04<- ifelse(df$referral <"2005-01-01" & df$closure > "2003-12-31" |  
df$closure== "", "Yes", "No")


if you are trying to account for the column closure containing NA values  
then:

df$Dec04<- ifelse(df$referral <"2005-01-01" & df$closure > "2003-12-31" |  
is.na(df$closure)== "TRUE", "Yes", "No")

not sure if how you have read your data in whether you included blanks in  
your NA strings or not?

Hope this helps,
Natalie

On Jul 10, 2010 2:29pm, "Wang, Kevin (SYD)" <kevinwang@kpmg.com.au> wrote:
> Hi,



> I'm trying to check a column of dates and creating indicator variables  
> showing different time periods.



> For example, if I were to do this in Excel I would have something like:

> Year to Dec 2004=IF(AND(referral dateDATE(2003,12,31), LEN($closure date)  
> = 0)), "Yes", "No")

> for the "Year to Dec 2004" column.



> I've read the data into R and converted the two columns (referral date  
> and closure date) to as.Date() format (found this format from r-help):

> referral
> closure


> But then have trouble doing the "if" checking. I tried something like:

> Dec04
> (closure > as.Date("31/12/2003", "%d/%m/%Y") || closure  
> = ""), "Yes", "No")



> but got an error message:

> Error in closure > as.Date("31/12/2003", "%d/%m/%Y") || closure = "" :

> could not find function "||


> I haven't really played with dates in R before so would really appreciate  
> some guidance on this.



> (I'm avoiding Excel because there are over 130,000 rows to check, and I  
> need to repeat this process for each quarter since Dec 2004. When I tried  
> this in Excel it just took all the memory I have on my computer and  
> freezes the entire workbook).



> Cheers

> Kevin





> Kevin Wang

> Senior Advisor, Health and Human Services Practice

> Government Advisory Services



> KPMG

> 10 Shelley Street

> Sydney NSW 2000 Australia



> Tel +61 2 9335 8282

> Fax +61 2 9335 7001



> kevinwang@kpmg.com.au











> ******************************************************************



> The information in this e-mail is confidential and may be legally

> privileged. It is intended solely for the addressee. Access to this

> e-mail by anyone else is unauthorised. If you have received this

> communication in error, please notify us immediately by return

> e-mail with the subject heading "Received in error" or telephone

> +61 2 93357000, then delete the email and destroy any copies of it.

> If you are not the intended recipient, any disclosure, copying,

> distribution or any action taken or omitted to be taken in reliance

> on it, is prohibited and may be unlawful. Any opinions or advice

> contained in this e-mail are subject to the terms and conditions

> expressed in the governing KPMG client engagement letter. Opinions,

> conclusions and other information in this e-mail and any

> attachments that do not relate to the official business of the firm

> are neither given nor endorsed by it.



> KPMG cannot guarantee that e-mail communications are secure or

> error-free, as information could be intercepted, corrupted,

> amended, lost, destroyed, arrive late or incomplete, or contain

> viruses.



> KPMG, an Australian partnership and a member firm of the KPMG

> network of independent member firms affiliated with KPMG

> International Cooperative (“KPMG International”), a Swiss entity.

> KPMG International provides no services to clients.



> Liability limited by a scheme approved under Professional Standards

> Legislation.



> *

> ______________________________________________

> R-help@r-project.org mailing list

> https://stat.ethz.ch/mailman/listinfo/r-help

> PLEASE do read the posting guide  
> http://www.R-project.org/posting-guide.html

> and provide commented, minimal, self-contained, reproducible code.


	[[alternative HTML version deleted]]

