Q:

Write a R program to compare two data frames to find the row(s) in first data frame that are not present in second data frame

0

Write a R program to compare two data frames to find the row(s) in first data frame that are not present in second data frame.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

df_90 = data.frame(
  "item" = c("item1", "item2", "item3"),
  "Jan_sale" = c(12, 14, 12),
  "Feb_sale" = c(11, 12, 15),
  "Mar_sale" = c(12, 14, 15)
)
df_91 = data.frame(
  "item" = c("item1", "item2", "item3"),
  "Jan_sale" = c(12, 14, 12),
  "Feb_sale" = c(11, 12, 15),
  "Mar_sale" = c(12, 15, 18)
)
print("Original Dataframes:")
print(df_90)
print(df_91)
print("Row(s) in first data frame that are not present in second data frame:")
print(setdiff(df_90,df_91))

Sample Output:

[1] "Original Dataframes:"
   item Jan_sale Feb_sale Mar_sale
1 item1       12       11       12
2 item2       14       12       14
3 item3       12       15       15
   item Jan_sale Feb_sale Mar_sale
1 item1       12       11       12
2 item2       14       12       15
3 item3       12       15       18
[1] "Row(s) in first data frame that are not present in second data frame:"
  Mar_sale
1       12
2       14
3       15

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now