You can achieve this using the apply
function in R, which applies a function to each row of a dataframe. Here's a sample code snippet:
main.r735 chars32 lines
In this code:
df1
and df2
.remove_variables
that takes a row from df1
and the entire df2
dataframe as arguments.df2
.ifelse
to replace values that match the values in the current row of df1
with NA
.df1
using a for
loop.df2
dataframe.Note that this code assumes that the values in df1
and df2
are characters. If the values are of different types, you may need to adjust the comparison accordingly.
gistlibby LogSnag