lundi 19 février 2018

How to use for and If to compare two dataframes?

I would like to compare the variable "Name" in the dataframes and if the values are the same, print that value, this is what I´m doing:

x <- data.frame("SN" = 1:4, "Age" = c(21,15,30,40), "Name" = c("Isa","Dora","Luisa","Daniela"))
x

y <- data.frame("SN" = 1:4, "Age" = c(22,17,36,41), "Name" = c("Isa","Cristian","Peter","Juan"))
y

y$Name

i

for (i in "y$Name"){
  if (i = "x$Name" ){
    print(i)
  }
 next
}

Aucun commentaire:

Enregistrer un commentaire