Reputation: 173
if I have a table like
table 1
id name
1 A
2 D
3 B
4 C
table 2
id name
2 A
3 A
4 D
5 D
table 3
id name
1 D
3 B
4 B
5 D
if m1 <- table 1 and m2 <- table2 and m3 <- table3, what I did is:
aPid <-Reduce(intersect, list(m1$id,m2$id,m3$id))
and I want to update tables based on intersected id such as:
m11 <- applyIndexToDataFrame(m1, m1$id %in% aPid)
m22 <- applyIndexToDataFrame(m2, m2$id %in% aPid)
m33 <- applyIndexToDataFrame(m3, m3$id %in% aPid)
'applyIndexToDataFram' is not real function. I just made up
Then finally:
table 1
id name
3 B
4 C
table 2
id name
3 A
4 D
table 3
id name
3 B
4 B
Is there any function to update tables based on intersected data in R?
Upvotes: 0
Views: 56
Reputation: 3647
Your "applyIndextoDataFrame" function can be achieved just by using bracket sub-setting notation:
m11 <- m1[m1$id %in% aPid,]
You can do it in one call if you like as:
m11 <- m1[m1$id %in% Reduce(intersect, list(m1$id,m2$id,m3$id)),]
Upvotes: 1