[R] Processing key_column, begin_date, end_date in R

JS Huang js.huang at protective.com
Thu Feb 26 05:18:36 CET 2015


Hi,
  
  Here is an implemenation:

> date
  key_column begin_date    end_date
1     123456 2013-01-01 2014-01-01 
2     123456 2013-07-01 2014-07-01 
3     789102 2012-03-01 2014-03-01 
4     789102 2015-02-01 2016-02-01 
5     789102 2015-02-06  2016-02-06
> y <- t(sapply(unique(date$key_column),function(x)
> c(x,min(as.character(date[date$key_column==x,"begin_date"])),max(as.character(date[date$key_column==x,"end_date"])))))
> y
     [,1]     [,2]         [,3]         
[1,] "123456" "2013-01-01" "2014-07-01 "
[2,] "789102" "2012-03-01" "2016-02-06" 
> colnames(y)
NULL
> colnames(y) <- c("key_column","begin_date","end_date")
> y
     key_column begin_date   end_date     
[1,] "123456"   "2013-01-01" "2014-07-01 "
[2,] "789102"   "2012-03-01" "2016-02-06" 



--
View this message in context: http://r.789695.n4.nabble.com/Processing-key-column-begin-date-end-date-in-R-tp4703835p4703850.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list