I'm trying to apply a function to a list of two-dimensional data.
The data I am working on takes measurements over time from many probes. I apply a time index to the matrix that resets when the probe changes.
I have achieved this by transforming the list into individual dataframes, however, I would like to use something from the lapply() family to achieve this as my dataset grows.
This is the individual matrix approach that works:
source = c(1,1,1,2,2,2,3,3,3,4,4,4)
df1 = data.frame(source)
df1$elapsedTime <- (ave(df1$source, df1$source, FUN = seq_along))
df
# source elapsedTime
# 1 1 1
# 2 1 2
# 3 1 3
# 4 2 1
# 5 2 2
# 6 2 3
# 7 3 1
# 8 3 2
# 9 3 3
# 10 4 1
# 11 4 2
# 12 4 3
I would like to use a function from Map family for this process over a list of similar matrices from different experiments.