Using r if I have a data frame that contains dates and temperatures.

I would like to pull out all temperatures for January how would I go about

phrasing this. I've tried may ways such as

louisville_weather <- filter(louisville_weather$DATE <= 2013-01-31)
  • $\begingroup$ I think stackoverflow.com would be more appropriate for your question, as this is rather a coding issue rather than a Data Science question. $\endgroup$
    – Partha D.
    Commented Jan 5, 2019 at 12:17
  • $\begingroup$ Hey friend, r programming is for data science. Where is the best place to find fast answers: of course the data science stack exchange! $\endgroup$
    – Chris Kehl
    Commented Jan 6, 2019 at 11:52
  • $\begingroup$ Sorry @Chris Kehl if you have misunderstood me. Not that it's an incorrect or inappropriate post, but you might get more peers and hence quicker (and possibly more varied) answers on stackoverflow. Particularly since people don't have to know data science in order to answer this particular question-- but knowledge in R would be fine. However then, I would have missed the chance of answering it (and getting kudos) since someone else must surely have posted a good enough answer before me ! Thanks, anyway, dear friend. $\endgroup$
    – Partha D.
    Commented Jan 6, 2019 at 14:05

1 Answer 1


If louisville_weather$DATE is formatted as POSIXct, the month can be extracted, thanks @RockScience, with

lvmonth <- format(louisville_weather$DATE, "%m")

It's a character variable. So, filtering

louisville_weather <- louisville_weather[lvmonth == "01", ]

should extract your weather for January.

Hope you'll find it cold enough to balance the warmth of datascience.SX !


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.