Ravula Abhigyan
Ravula Abhigyan

Reputation: 65

Merging data frames such that Time column remains unique in R

Hello, I am trying to merge these two data frames such that there's only one unique time column and an additional column called TYPE is created which is attributed to PK (TYPE==1) or PD (TYPE==2) for their respective times. I have never done something like this before, any help would be highly appreciated.

    temptime<-c(0,1,2,3,4,5,6)
    tempconc<-c(0:6)
    PK<-cbind(temptime,tempconc)
    temppdtime<-c(0,2,5,7,9)
   temppd<-c(100:104)
   PD<-cbind(temppdtime,temppd)
   PKPD<-merge(PK,PD)
   PKPD

Thank you.

Upvotes: 0

Views: 51

Answers (1)

Mr. Bugle
Mr. Bugle

Reputation: 325

Rename your time variables to be the same in both PK and PD. Then create the TYPE variable in each PK and PD, filled out with 1 or 2 for the respective dataframe. Then rbind PK and PD.

Upvotes: 1

Related Questions