0

I am working on an analysis where I have 2 datasets, one with temperature and the other with crimes. For every crime in the data frame, I want to add a column to show what the temperature was that hour. Any guidance would be appreciated. Thanks!

  • 1
    Welcome to SO Keith. For future posts, please review [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) SO post about making reproducible examples for R questions. [Here](https://stackoverflow.com/help/minimal-reproducible-example) you can find a language agnostic guide. RepExp help the community help you. – Daniel Jun 27 '21 at 21:48
  • 1
    Additionally, before asking run a search of past questions. This one, in particular, has been very thoroughly answered [here](https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right?rq=1). – Daniel Jun 27 '21 at 21:52
  • 2
    Does this answer your question? [How to join (merge) data frames (inner, outer, left, right)](https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-left-right) – Daniel Jun 27 '21 at 21:53

1 Answers1

1

Usually both datasets should have a feature (or multiple) in common. When these are in place you can use the "joins" to join the datasets together. Example below:

library(dplyr)

df1 <- data.frame(date, crime)
df2 <- data.frame(date, tmp)
df <- inner_join(df1, df2, by = "date")

Note that this is a inner join but depending on the datasets it could be necessary to use left or full joins. Without a sample dataset we can't help more.

SUR93
  • 46
  • 4