-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
|
||
# Please fill in the following constants according to your folder/file names | ||
wd <- "~/Desktop/r_wd" | ||
user_filename <- "user_data.csv" | ||
dcw_filename <- "dcw_data.csv" | ||
user_colname = "zip" | ||
dcw_colname = "zipCode" | ||
output_filename <- "merged_data.csv" | ||
|
||
# Load the 'dplyr' package. If it's not installed, run install.packages("dplyr") | ||
library(dplyr) | ||
|
||
# (Optional) Set your working directory | ||
setwd("/path_to/your_working_directory") | ||
# Set working directory | ||
setwd(wd) | ||
|
||
# Read the user's data into a data frame | ||
df1 <- read.csv("/path_to/your_data_file.csv", header = T) | ||
# Read the user's data | ||
df1 <- read.csv(user_filename, header = T) | ||
|
||
# Read the downloaded Data Commons CSV file into a new data frame | ||
df2 <- read.csv("/path_to/dcw_data.csv", header=T) | ||
df2 <- read.csv(dcw_filename, header=T) | ||
|
||
# Merge the two data frames using the appropriate column names | ||
col1 = "zip" | ||
col2 = "zipCode" | ||
merged_df <- left_join(df1, df2, by=setNames(nm=col1, col2)) | ||
merged_df <- left_join(df1, df2, by=setNames(nm=user_colname, dcw_colname)) | ||
|
||
# (Optional) Export merged data to CSV | ||
write.csv(merged_df, "/path_to/merged_data.csv", row.names = F) | ||
# Export merged data to CSV | ||
write.csv(merged_df, output_filename, row.names = F) |