Hello, Can someone help me on how to make a subset of my dataframe using two dates. This is what I have tried, but no data is being excluded in the new frame. six_months<-subset(Two_years, vdate>2011-01-01|vdate<2011-07-01) or all data is excluded six_months<-subset(Two_years, vdate>2011-01-01&vdate<2011-07-01) -- View this message in context: http://r.789695.n4.nabble.com/Subset-based-on-a-date-range-tp4630595.html Sent from the R help mailing list archive at Nabble.com.
Hello, You are not using dates. > 2011-01-01 [1] 2009 > 2011-07-01 [1] 2003 > as.Date(2011-07-01) Error in as.Date.numeric(2011 - 7 - 1) : 'origin' must be supplied > as.Date("2011-07-01") [1] "2011-07-01" The error is because as.Date is seeing 2003 as a number, the number of days since an unspecified origin. The solution for your problem would be to quote the dates. > Sys.Date() > "2011-07-01" [1] TRUE (And if you want to keep the dates between your two limits, '&' is the operator to use.) Hope this helps, Rui Barradas ** *> *May 19, 2012; 2:34pm ? by Allen <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=368527> Allen <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodes&user=368527> > Hello, *> * *> *Can someone help me on how to make a subset of my dataframe using two dates. This is what I have tried, but no data is being excluded in the new frame. *> * *> *six_months<-subset(Two_years, vdate>2011-01-01|vdate<2011-07-01) *> * *> *or all data is excluded *> * *> *six_months<-subset(Two_years, vdate>2011-01-01&vdate<2011-07-01) *> *
On 19.05.2012 15:34, Allen wrote:> Hello, > > Can someone help me on how to make a subset of my dataframe using two dates. > This is what I have tried, but no data is being excluded in the new frame. > > six_months<-subset(Two_years, vdate>2011-01-01|vdate<2011-07-01)Convert the *string* "2011-01-01" to a date format that corresponds to vdate, see e.g. ?strptime. Uwe ligges> or all data is excluded > > six_months<-subset(Two_years, vdate>2011-01-01&vdate<2011-07-01) > > > -- > View this message in context: http://r.789695.n4.nabble.com/Subset-based-on-a-date-range-tp4630595.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 guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.