[R] a difficult situation, how to do this using base function.
Stephen HonKit Wong
stephen66 at gmail.com
Fri Jul 21 21:22:36 CEST 2017
Hello,
I have a following dataframe with many rows.
data.frame(match.start=c(5,10,100,200),range.coordinates=c("1000-1050","1500-1555","5000-5050,6000-6180","100-150,200-260,600-900"))
match.start range.coordinates
5 1000-1050
10 1500-1555
100 5000-5050,6000-6180
200 100-150,200-260,600-900
I want to test for each row element in column "match.start" (e.g. 100 on
3rd row) if it is less than the accumulated range (e.g. for 5000-5050,
6000-6180, the accumulated range is: 50, 230), then update the match start
as 6000+ (100-50) = 6050. The result is put on third column.
match.start range.coordinates match.start.updated
5 1000-1050 1005
10 1500-1555 1510
100 5000-5050,6000-6180 6050
200 100-150,200-260,600-900 690
Many thanks.
[[alternative HTML version deleted]]
More information about the R-help
mailing list