Merging DataFrames

R also provides a built-in command, merge, in order to join DataFrames. Let us create a separate DataFrame with the geographic location of the center of each state (Latitude and Longitude):

state2 <- data.frame(State=state.name, Latitude=state.center$y, Longitude=state.center$x) # The syntax for merge is as follows: ## S3 method for class 'data.frame' # merge(x, y, by = intersect(names(x), names(y)), # by.x = by, by.y = by, all = FALSE, all.x = all, all.y = all, # sort = TRUE, suffixes = c(".x",".y"), # incomparables = NULL, ...) # Arguments # x and y = the DataFrames we want to merge # by = the column names by which we want to perform the merge # Note that since this can be different (if say the same column had different ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.