Hi, I have the following type of data:
myData <- data.frame(x = 1:5, y = letters[1:5], xDate = seq(as.Date("2001/2/1"), as.Date("2005/2/1"), by="year") ) > myData x y xDate 1 a 2001-02-01 2 b 2002-02-01 3 c 2003-02-01 4 d 2004-02-01 5 e 2005-02-01 What I need is a new column, say xDate2, that for each xDate (or for each unique combination of x,y, and xDate), I will have few days before and few days after, as follow: myData x y xDate xDate2 1 a 2001-02-01 2001-01-30 1 a 2001-02-01 2001-01-31 *1 a 2001-02-01 2001-02-01* (original row) 1 a 2001-02-01 2001-02-02 1 a 2001-02-01 2001-02-03 2 b 2002-02-01 2002-01-30 2 b 2002-02-01 2002-01-31 *2 b 2002-02-01 2002-02-01* (original row) 2 b 2002-02-01 2002-02-02 2 b 2002-02-01 2002-02-03 ... 5 e 2005-02-01 2005-01-30 5 e 2005-02-01 2005-01-31 *5 e 2005-02-01 2005-02-01 *(original row) 5 e 2005-02-01 2005-02-02 5 e 2005-02-01 2005-02-03 The actual xDate on my data is not as nicely sequenced as the above example. But the idea is the same, that I would like to get few days before and after for my each xDate. I've tried tapply, by and direct assignment like myData$xDate2 <- seq(xDate - 5, xDate + 5, by="day") and the like, but without result. Any idea is appreciated. Thanks much, Ferry [[alternative HTML version deleted]] ______________________________________________ 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.