Integrating Sample Data in R

I want to integrate data from one data block (A) selectively into another (B). The conditions are as follows. Data frames have two columns (miRNA and Gene). Dataframe A also contains a column with a value for the pair.

I want to create a new column in dataframe B that is taken from the Value column in and contains the value if the pair (same miRNA and Gene from row in A) matches B. If the pair does not match in B, create a new row with a score.


#Initialize column in B that will house A value if first two columns match
B$A_Values <- 0

If A[,1:2] == B[,1:2]:
     Change initialized B$A_Value to A[VALUE] of row from A[,1:2]

If A[,1,2] is not in B[,1:2]: 
     Add row in B[,1:2] 
     Change initialized B$A_Value to A[Value] of row from A[,1:2]


The data bands are not the same length, and no items not found in A will be found in B, although I assume my default initialization will be 0. Any help would be appreciated.



source to share

1 answer

This is what the function does merge


AB <- merge(A, B, by = c("miRNA", "Gene"), all = TRUE)


or if A

there are values ​​in that are not in B

and you want to remove those values, use

AB <- merge(A, B, by = c("miRNA", "Gene"), all.y = TRUE)




All Articles