Efficient way of labelling based on start and end position
问题 I have 2 dataframes das <- data.frame(val=1:20, type =c("A","A","A","A","A","A","B","B","B","B","B","B","B","B","B","B","C","C","C","C"), weigh=c(20,22,23,32,34,54,19,22,24,26,31,34,36,37,51,54,31,35,43,45)) mapper <- data.frame(type=c("A","A","A","A","B","B","B","B","C","C","C","C"),start = c(19,23,27,37 ,17,25,39,50, 17,23,33,39),end = c(23,27,37,55 ,25,39,50,60, 23,33,39,48)) The expected output is val type weigh labelweight 1 1 A 20 A_19 2 2 A 22 A_19 3 3 A 23 A_23 4 4 A 32 A_27 5 5 A 34