Hello!
How do I select the rows of a data.frame
according to some dates?
ex: select data from coluna 2
to dates 2016/12/15, 2016/12/25, 2017/01/08, 2018/01/01.
Hello!
How do I select the rows of a data.frame
according to some dates?
ex: select data from coluna 2
to dates 2016/12/15, 2016/12/25, 2017/01/08, 2018/01/01.
First I create a data.frame
with two columns, coluna1
(containing random values) and coluna2
containing some dates.
dados <- data.frame(coluna1 = rnorm(10), coluna2 = as.Date(c("2016/12/15", "2016/12/20", "2016/12/25", "2016/12/30", "2017/01/05", "2017/01/08", 2018/01/01", "2018/12/31", "2017/11/25", "2017/11/30")))
I separate the dates of interest:
datas <- as.Date(c("2016/12/15", "2016/12/25", "2017/01/08", "2018/01/01"))
I use the %in%
command to select the dates of the coluna2
containing the dates of interest
dados$coluna1[dados$coluna2%in%datas]