I've been stuck working on this for a little while now and I find it very hard to believe that this isn't an inbuilt function or that someone hasn't dealt with this before now.
The function I want to run should compare two columns of a dataframe by until they "best correlation is found. The data I am using is from two scientific instruments and their sampling/averaging times differ, which is why I want to shift the data.
date associated with only one element will be adjusted.
if correlation of data + x seconds is > that current correlation
increase current
note increasing
else if correlation of data - x seconds ix > than current correlation
decrease current date/time
not decreasing
end if
while correlation of data + x seconds is > than current correlation
increase current date/time by x seconds
end while
while correlation of data - seconds is > than current correlation
decrease current date/time by x seconds
end while
If there is a function that will do this great if not I will provide additional info + code
This is what my current code structure is. Date is POXISct 'GMT', Dusttrak is numeric, CO is numeric, color is a number I have created from time to give me a colored time series
I am currently using rcorr to find the correlation but date has been an issue, so I will either need to convert from date to numeric and back afterwards.