I have a dataframe, df
:
z x y
a T 1 F
b T 4 F
g F 7 T
a T 1 F
d T 2 T
d T 2 T
b T 4 F
g F 7 T
I also have a vector, v1
, like the following:
a 1
e 5
b 2
g 3
d 4
f 6
What I want to do is add this vector to my existing dataframe for only the rows that already exist in the dataframe:
z x y new
a T 1 F 1
b T 4 F 2
g F 7 T 3
a T 1 F 1
d T 2 T 4
d T 2 T 4
b T 4 F 2
g F 7 T 3
in psuedocode I want to do something like
for i in rownames(df):
if i in rownames(v1):
add v1 value of i to a new column, df$new