0

I have been trying to filter through a dataset for my research project. I have time stamps with both the year/month/ date and hour/min/sec included in the column "ts" (for time stamp).

I have been using the dplyr "filter" function as such:

filter(df.flat.subset1, (projID == "168", ts= 2017-08-03))

I keep getting 0 rows or this error

Error: unexpected numeric constant in:
filter(df.flat.subset1, projID == "168", ts == "2017-08-03 %H:%M:%S)

if I try to leave the time as unknown...

df.flat.subset1 is my data set (ignore projID it is simply my project 168 in a larger dataset of multiple projects) and the date at which i would like to filter is August 3rd 2017.

I have thousands of values for that date so I cannot specify the exact time but I would like to at least narrow this down.

Any idea how I could do this??

Much thanks

neilfws
  • 32,751
  • 5
  • 50
  • 63
Meg
  • 1
  • Please provide more code and don't forget to style it – mel Oct 16 '17 at 03:46
  • By `2017-08-03` do you really intend `2006`? And do you want `=` or `==` there? – r2evans Oct 16 '17 at 03:56
  • 2
    @mel, I'm not certain what you mean by "style it". Meg, providing a [reproducible question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (also [minimal, verifiable example](https://stackoverflow.com/help/mcve)) is very helpful to us, and will increase the likelihood and speed of getting a relevant response. As it stands, your code contains obvious syntax errors that should be giving different errors. – r2evans Oct 16 '17 at 03:58
  • @r2evans I meant use "the triple space and ` ` to write code" – mel Oct 16 '17 at 05:30

2 Answers2

1

I suggest using the lubridate package since it is easier to manipulate dates:

library(lubridate)
filter(df.flat.subset1, projID == "168", date(ts) == date('2017-08-03'))
twalbaum
  • 410
  • 1
  • 4
  • 12
0

You want format(ts, '%Y-%m-%d') == '2017-08-03' as your filter, if you want to ignore the timestamp.

You could also try as.Date(ts) == '2017-08-03'.

MichaelChirico
  • 33,841
  • 14
  • 113
  • 198