I am trying to write a function which will return all rows related to that id.
Input Data:
df <- data.frame(
id1=c('A1','A1','B1','B2','C2','C3','B3','D1','D2','E1'),
id2=c('P1','P2','P1','P2','P1','KK3','KK3','DL5','FD7','LO6')
)
E.g.
sample_rows <- function(id1){
#code here
return(output)
}
Desired Output 1:
sample_rows(id1='A1') should return following data frame:
id1 id2
A1 P1
A1 P2
B1 P1
B2 P2
C2 P1
Desired Output 2:
sample_rows(id1 = 'C3') should return following data frame:
id1 id2
C3 KK3
B3 KK3