r - Empty data frame from Date selection -


i have data frame 3262 rows , 10 columns. 1 of columns has date format yy-mm-dd. want store rows 10 different dates in different data frame tried :

newdata= df[df$date %in% as.date(c('2011-08-05','2012-1-13','2012-03-2','2014-04-01')),] 

but nothing. thought might need specify again format tried:

df$date <- as.date( as.character(df$date), "%d-%m-%y")  newdata= df[df$date %in% as.date(c('2011-08-05','2012-1-13','2012-03-2','2014-04-01')),] 

all empty data frame saying no data available in table. @ point made mistake (something stupid guess)?

i created example:

set.seed(1) df=data.frame(col1=seq(1,10),     col2=seq(1,0),     date=as.date(floor(runif(min=15550,max=17000,n=10)),origin="1970-01-01")) > df    col1 col2       date 1     1    1 2013-08-17 2     2    0 2014-01-19 3     3    1 2014-11-06 4     4    0 2016-03-06 5     5    1 2013-05-17 6     6    0 2016-02-21 7     7    1 2016-04-28 8     8    0 2015-03-14 9     9    1 2015-01-27 10   10    0 2012-10-26 

using same code provided:

newdata= df[df$date %in% as.date(c('2013-08-17','2015-01-27')),] 

gives me

> newdata   col1 col2       date 1    1    1 2013-08-17 9    9    1 2015-01-27 

are sure str(df$date) shows have date format?

> str(df$date)       date[1:10], format: "2013-08-17" "2014-01-19" "2014-11-06" "2016-03-06" "2013-05-17" "2016-02-21" "2016-04-28" "2015-03-14" "2015-01-27" "2012-10-26" 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -