-1

can some help me how to do this in R Programming?

Pl check the link i have same kind of situation

Check if value from one dataframe exists in another dataframe

Vinith
  • 19
  • 1
  • 5
  • yes the but the link you shared is in python, the answer is in python but i need it in R programming – Vinith Jul 06 '20 at 15:51
  • the link you shared is right one for python , the first answer of @piRSquared is given in python ... i am trying to bring the same result using R – Vinith Jul 06 '20 at 15:54
  • 1
    Please post data in a format that R can understand. – Rui Barradas Jul 06 '20 at 15:55
  • 2
    I think the history and connection to Python is not relevant and that it would be best if your wrote up the complete question with some reproducible R data and clear example of expected output. – s_baldur Jul 06 '20 at 15:56

2 Answers2

3

Using the same data and outcome as the original Python example

Df1 <- data.frame(name =  c('Marc', 'Jake', 'Sam', 'Brad'))
Df2 <- data.frame(IDs = c('Jake', 'John', 'Marc', 'Tony', 'Bob'))
Df1$presentinDf2 <- as.integer(Df1$name %in% Df2$IDs)
Df1
#>   name presentinDf2
#> 1 Marc            1
#> 2 Jake            1
#> 3  Sam            0
#> 4 Brad            0
Chuck P
  • 3,862
  • 3
  • 9
  • 20
2

I'm not sure if this is what you're looking for, but you can use anti_join from the dplyr package to create a new dataframe with the duplicate information between the datasets.

df1 <- data.frame(name =  c('Marc', 'Jake', 'Sam', 'Brad'))
df2 <- data.frame(name = c('Jake', 'John', 'Marc', 'Tony', 'Bob'))
diff <- anti_join(df2, df1, by = "name")

> diff
  name
1 John
2 Tony
3  Bob
millie0725
  • 359
  • 2
  • 12