Reputation: 113
I have two dataframes of same dimensions. But as shown I want to order the dataframe data
such that the id_num
is ordered in the order of id_num
of reference
. The output should look like the dataframe required
.
How can I do it?
reference <- data.frame(id_num=c(206,307,408,506), Event_1=0, Event_2=0)
data <- data.frame(id_num=c(506,307,408,206), Event_1=c(1,3,5,7), Event_2=c(2,4,6,8))
required <- data.frame(id_num=c(206,307,408,506), Event_1=c(7,3,5,1), Event_2=c(8,4,6,2))
Upvotes: 1
Views: 46
Reputation: 12112
merged <- merge(reference[,"id_num",drop=FALSE],data,by="id_num")
Upvotes: 2