0

I have two csv files. Shown in pictures.

Files are shown in the following link.

https://drive.google.com/drive/folders/1bDr9-gywQuVCcfp18JIwoybecTY-VYvP?usp=sharing

Following code are the current code I did. Now I have to merge table by PdId column.

I need to have the overview of the San Francisco crime data.

Thanks

library(data.table)

fread("~/datasets/crime_location.csv")

fread("~/datasets/crime_detail.csv")

df1 <-("~/datasets/crime_location.csv")

df2 <-("~/datasets/crime_detail.csv")

楊東翰
  • 9
  • 1
  • 5
  • Try `df3 <- merge(df1, df2, by = 'PdId')`. – Ronak Shah Nov 04 '20 at 02:53
  • I have try it. These are the error message : **Error in fix.by(by.x, x) : 'by' must specify a uniquely valid column** – 楊東翰 Nov 04 '20 at 02:55
  • Please add data using `dput` or something that we can copy and use. Images are not helpful. Read about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and [how to give a reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Nov 04 '20 at 02:56
  • Thanks. I put the link on the web. You could click the link and download it. – 楊東翰 Nov 04 '20 at 03:05
  • Are both the columns called `PdId` ? Did you read the data into R? `df1 <- fread("~/datasets/crime_location.csv")` and same for `df2` ? – Ronak Shah Nov 04 '20 at 04:23
  • Yes, I did it the same for f2. RStudio could read both data frame. – 楊東翰 Nov 04 '20 at 05:32

2 Answers2

0

You fread something into a variable. This is probably it.

library(data.table)
loc=fread("~/datasets/crime_location.csv")
det=fread("~/datasets/crime_detail.csv")
df3=merge(loc, det, by = 'PdId')
kana
  • 605
  • 7
  • 12
0

You can try this one.

library(dplyr)
df1 <- as.data.frame(df1)
df2 <- as.data.frame(df2)

df1$PdId <- as.character(df1$PdId)
df2$PdId <- as.character(df2$PdId)
df3 <- full_join(df1, df2, by = "PdId")
Kian
  • 110
  • 7