I have 70 columns and more than 400k rows .In the data date column will have values from 1900(01/01/1900) .How do i select only the data of recent two years?Help me in this regard -- View this message in context: http://www.nabble.com/Selecting-data-based-on-date-Data-manupulation-tp25530189p25530189.html Sent from the R help mailing list archive at Nabble.com.
Hi see ?format output of format can be transferred to numeric and you can use logical operators to select only desired data. x[as.numeric(format(x, "%Y")) > 2008,] another option is to compare it to some date like x > as.Date("2008-1-1") this assumes that x has class "Date". If not you can change it by as.Date function. Regards Petr r-help-bounces at r-project.org napsal dne 21.09.2009 07:55:57:> > I have 70 columns and more than 400k rows .In the data date column willhave> values from 1900(01/01/1900) .How do i select only the data of recenttwo> years?Help me in this regard > -- > View this message in context:http://www.nabble.com/Selecting-data-based-on-> date-Data-manupulation-tp25530189p25530189.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On 09/21/2009 03:55 PM, premmad wrote:> I have 70 columns and more than 400k rows .In the data date column will have > values from 1900(01/01/1900) .How do i select only the data of recent two > years?Help me in this regard >Hi premmad, First, find out what the two most recent dates are: two_recent_dates<- sort(strptime(mydata$date,format="%d/%m/%Y")),TRUE)[1:2] then get the row indices of those dates. which(strptime(mydata$date,format="%d/%m/%Y") %in% two_recent_dates) then select your rows: mydata[two_recent_dates,] Jim