Fetch data from one data frame from the data in another

Asked

Viewed 111 times

1

I’m on a quest I can’t solve. The problem is this: I have two tables and I need to research if there are equal people in the two tables, in case I need to see how much it earns in the second table and transport to the first (in a new column), but it ends up taking the values 'randomly', below is the code I made:

pensionista.especial <- read.xlsx("PensaoEspecial.xlsx")
pensionista.janeiro <- read.xlsx("PensaoMensal12.xlsx")

pensionista.janeiro <- transform(pensionista.janeiro, PensaoEsp = ifelse(ID.FUNCIONAL %in% pensionista.especial$ID.FUNCIONAL,
                                                                         1 ,0))

pensionista.janeiro <- transform(pensionista.janeiro, InstEsp = ifelse(ID_FUNCIONAL_INSTITUIDOR %in% pensionista.especial$ID_FUNCIONAL_INSTITUIDOR,
                                                                       1, 0))

basedetrabalho <- pensionista.janeiro[ , c(1,10,13,14,23,31,32,33,34,69, 78, 79)]

basedetrabalho <- transform(basedetrabalho, VB_ESP = ifelse(ID.FUNCIONAL %in% pensionista.especial$ID.FUNCIONAL, pensionista.especial$VL_BRUTO, 0))

I ask for help with this personal problem!

1 answer

1

I already got the solution, it was through the merge function

merge(pensionista.janeiro, pensionista.especial[,c("ID.FUNCIONAL","VL_BRUTO")],
  by.x = "ID.FUNCIONAL", by.y = "ID.FUNCIONAL", all.x = TRUE)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.