Saving rows of a data frame based on the values of a column of another data frame

2

I have a dataframe with 50 rows and 10 columns and one with 10 rows and 5 columns, the first column of both dataframes can have equal values. How do I select and save rows, only, from the first date frame following the condition that the rows (from the first column) of the second data frame should be the same?

    
asked by anonymous 30.10.2017 / 06:15

1 answer

3

I created two dataframe to exemplify

A <- data.frame(X = sample(LETTERS, 50, rep = T), Y = rnorm(50), Z = rpois(50, 3))
B <- data.frame(X1 = sample(LETTERS, 10, rep = T), Y1 = rnorm(10))

For you to get the rows of the first column of A that have equal values in the rows of the first column of B , you can use the command below. I saved in dataframe C

C <- A[which(A$X %in% B$X1),]
    
30.10.2017 / 11:40