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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.