I have a list of data frames, each having rows with a 3-dimensional vector (3 columns). I would like to compute the cosine similarity (lsa::cosine) on each subsequent pair of rows in each data frame (e.g., rows 1 and 2, 2 and 3, 3 and 4, etc.). How can I loop through each data frame in the list to calculate the cosine similarities of subsequent rows, keeping the cosine values separate for each data frame?
Here is some easy fake data for reproducibility purposes:
df1 = data.frame(y1 = c(1,2,3,4,5), y2 = c(2,3,4,5,6), y3 = c(5,4,3,2,1))
df2 = data.frame(y1 = c(6,7,8,9,10), y2 = c(6,5,4,3,2), y3 = c(1,3,5,7,9))
dflist = list(df1, df2)
Thanks in advance!