Monday 15 September 2014

Select subset by date in R -


I have a file and I have to select only those children who were born before 2004.

Example

  n_child gender date_born 1m 20/03/2002 2m 09/08/2001 3F 01/09/2003 4m 07/05/2003 5 M 12/09/2004 6F 19/08/2004   

I want

  n_child gender date_born 1m 20/03/2002 2m 09 / 08/2001 3F 01 / 09/2003 4M 07/05/2003   

I tried the following, but it does not work:

  Dates & lt; - (As of. (Df $ date_born) $ year) & lt; 2004 dat & lt; - df [datesub,]    

If you use another package (lubricate) For this, it should work, except for other things, use the LIBRIDITS DATES date just ymd ('datestring') where y is the year, month of the month and d on that day It is when they are in the string that you are trying to parse. & gt; Df n_child gender date_born 1 1m 20/03/2002 2 2m 09/03/2001 3 3F 01/09/2003 4 4M 07/05/2003 5 5m 12/09/2004 6 F 6/8/08 / 2004 & gt; Required (lubricated) & gt; Df $ dateborn & lt; - dmy (df $ date_born) 6% parsed% d /% m /% y & gt; Dates & lt; - df [df $ date_born & lt; Ymd (20040101), 1 %% y% m% d & gt; Number of dates n_child gender date_born 1 1m 2002-03-20 2 2m 2001-03-09 3 3F 2003-09-01 4 4M 2003-05-07

No comments:

Post a Comment