Entering edit mode
4.6 years ago
hoc307
•
0
Hi There. I need some help to create a function that will allow me to match the date and value from one dataframe to another (with the date specific score), so the date/value could be scored . Please see the following lines of code in 3 parts 1) dataframe (df1) with date-row value that needs to be scored, 2) dataframe (df2) containing some (but not all) date-value scores. 3) The desired resulting dataframe with two columns containing the highest score and the corresponding row value. I would really appreciate your help! Thanks!
#creating the first dataframe(df1) where column values (a1, a2) need to match with dates from another dataframe (df2) to compute for a higher score
date1<- c("5-5-2020","4-5-2020","5-5-2020","4-5-2020","5-5-2020","4-5-2020")
a1<- c("A","B","B","B","C","C" )
a2<- c("NA","A","A","NA","A","B" )
df1<-cbind(date1,a1,a2)
view(df1)
#second dataframe (df2) with dates and score available, note it may not have all the dates and values matched with df1
date2<- c("2020-05-05","2020-05-04","2020-05-05","2020-05-04","2020-05-05")
b1<-c("A","A","B","B","C")
score<- c(50,10,70,30,10)
df2<-cbind(date2,b1,score)
view(df2)
#Results to be displayed by matching date1 with date2 for each a1 vs a2's corresponding to the one higher value on the variable score from df2
c1<-c(50,30,70,30,50,30)
c2<-c("A","B","B","B","A","B")
df3<- cbind(df1,c1,c2)
view(df3)
This is not a bioinformatics question but an R programming one. Try the R channel on Stack Overflow.