example_df <- function(intext) {
tf <- tempfile()
writeLines(intext, con = tf)
require(tidyverse)
as_tibble(read.delim(tf,sep=";"))
}
(df <- example_df("
row;value
1;119629-19
2;3,750 TL
3;70383-4024
4;48256-550
5;1,300 TL
6;9842-4913
7;104146-243
8;63839-1196
9;1,500 TL
10; 1718-1974
11; 1718-1973
12; 119808-7
13; 3,000 TL
14; 2957-714
15; 5,500 TL
16; 117842-24
17; 1718-1948
18; 1718-1949
19; 1718-1760
20; 1718-1966
21; 1718-1801
22; 1718-1829
23; 119257-4
24; 119257-1"))
(idlist <- filter(df,
str_detect(value,"TL",negate = TRUE)) %>% mutate(
nextidrow = lead(row)
))
(pricelist <- filter(df,
str_detect(value,"TL",negate = FALSE)))
library(fuzzyjoin)
fuzzyjoin::fuzzy_left_join(idlist,
pricelist,
by=c("row"="row",
"nextidrow"="row"),
match_fun = list(
`<`,`>`
)) %>%
select(ID=value.x,
price =value.y)