fuzzyjoin icon indicating copy to clipboard operation
fuzzyjoin copied to clipboard

example suggestion

Open mjwebster opened this issue 6 years ago • 1 comments

Thank you for this package! I used it for assigning people to generations (Boomers, Millenials, etc) depending on the year they were born (also possible to base it on age using that as a rough approximation of year they were born, but that's more complicated code). Here's some simplified code of how I used fuzzyjoin.

library(fuzzyjoin)

#create generations table name <- c("Generation ?", "Generation Z", "Millenials", "Xennials", "Generation X", "Baby Boomers","Silent")

startyr <- c(2017, 1997, 1984, 1977, 1963, 1944, 1900)

#there's a dummy year in here for Generation ? endyr <- c(2025, 2016, 1996, 1983, 1976, 1962, 1943)

generations <- data.frame(name, startyr, endyr)

#create a data table of people with the year they were born name <- c("person1", "person2", "person3", "person4", "person5", "person6", "person7", "person8", "person9")

yr_birth <- c(1971, 2018, 1999, 1917, 1965, 1949, 1979, 1983, 1989)

people <- data.frame(name, yr_birth)

#Update the people table to indicate what generation they belong to #depending on whether their birth year falls on or after start yr and on or before end year of the generation

people <- fuzzy_left_join( people, generations, by = c( "yr_birth" = "startyr", "yr_birth" = "endyr" ), match_fun = list(>=, <=))

mjwebster avatar Dec 11 '19 18:12 mjwebster

Very cool :)

This worked until the very last line ("people <- fuzzy... "):

Error in parse(text = x, srcfile = src): :4:122: unexpected '>='

Do you have suggestions?

Best, Chris

chriseshleman avatar Sep 23 '21 18:09 chriseshleman