I have some data frames, as follows
jack<-data.frame(c("M","F"),c(12,22))
colnames(jack)[1]<-"sex"
colnames(jack)[2]<-"age"
ethan<-data.frame(c("M","F"),c(34,99))
colnames(ethan)[1]<-"sex"
colnames(ethan)[2]<-"age"
ellie<-data.frame(c("M","F"),c(9,35))
colnames(ellie)[1]<-"sex"
colnames(ellie)[2]<-"age"
And a final data frame
mydf<-as.data.frame(c("martha","jack","luis","ethan","ellie"))
colnames(mydf)[1]<-"name"
I want to create a data frame with the value from the column sex of each data frame (jack, ethan, ellie), matching the name column of mydf (if there's a match - otherwise, put a 0). The final result should look like this
name sexM sexF
1 martha 0 0
2 jack 12 22
3 luis 0 0
4 ethan 34 99
5 ellie 9 35
I cannot understand how to combine these data frames. I used merge in the past, but this time I don't want to match row or column names, but the data frame (jack) with its matching row in mydf and insert its age value in the column.