Big_Data_Slip_3

Slip No.3

1) Write an R program to compare two data frames to find the elements in first data frame that are not present in second data frame.

    # Define the first data frame
    df1 <- data.frame(
    ID = c(1, 2, 3, 4, 5),
    Name = c("Alice", "Bob", "Charlie", "David", "Eve"),
    Score = c(85, 92, 78, 88, 95)
    )

    # Define the second data frame
    df2 <- data.frame(
    ID = c(2, 3, 6),
    Name = c("Bob", "Charlie", "Frank"),
    Score = c(92, 78, 81)
    )

    # Find rows in df1 that are not present in df2
    diff_df <- setdiff(df1, df2)

    # Print the result
    print("Elements in df1 not present in df2:")
    print(diff_df)

No comments:

Post a Comment