r - Compare each row value to multiple rows and return a value -
i trying following in r.
i have data frame time(hour) , second column has either 0 or one. time interval between consecutive time step 1 hour. easier if attach sample file don't know how attach one. trying find out how many 1's occur 24-hour apart. more 1 "1" in 24 hour period considered "1"
let's assume counter, cnt initialized @ 0.
i want compare each of row in second column second column values in 24 hour window. if there more 1 "1" in 24-hour period, implies there 1 "1" in 24-hour window.
in fortran, set counter, go each time step, compare value next 24 hours/time steps. if "1" found, first "1" increase counter 1. if there "1" in same 24-hour period, not increase counter more , move next row , keep doing until end of file.
hopefully, explain want. if it's not clear, let me know. think can done match() function or plyr package cannot find out.
the iranges package in bioconductor can here. first, calculate running sum of score
windows of size 24. cap sums @ 1.
rs <- iranges::runsum(score, 24) pmin(rs, 1)
is want? might want play endrule
parameter.
Comments
Post a Comment