How to do Excel VLOOKUP in R (using left_join, merge)
[This article was first published on r-bloggers on Programming with R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This tutorial helps you code Excel’s VLOOKUP (Exact Match) functionality in R using dplyr’s left_join() and Base-R’s merge(). Please let me know your feedback if this can help Excel users try out R and get confident about doing Data Analytics in R
Youtube – https://www.youtube.com/watch?v=GsxlOwa4dSg
Video Tutorial
Code
# library tidyverse for data manipulation and plot
library(tidyverse)
# reading input dataset
co2 <- read_csv("C:/users/abdrs/Downloads/food_consumption.csv")
countries <- read_csv("C:/users/abdrs/Downloads/Countries-Continents.csv")
countries$some_number <- 6
# method 1
co2 <- co2 %>%
left_join(countries, by = c('country' = 'Country'))
# method 2
co2 <- merge(co2, countries,
by.x = 'country',
by.y = "Country")
To leave a comment for the author, please follow the link and comment on their blog: r-bloggers on Programming with R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.