I have two lists, list1 and list2 which has 77103 elements each with each row being a dataframe with 1 row and 100 columns. I am trying to do linear interpolation using approx function in R and I get the following error.
***`Error in Y[row, ] : incorrect number of dimensions`***
Here is an example code for what I am trying to do.
a1<- c(2.5, 7.8, 6.5, 9.2, 10.2)
a2<- c(1.1, 2.5, 3.9, 7.2, 11.2)
a3<- c(2.7, 5.8, 7.2, 12.2, 14.2)
a<- as.list(data.frame(a1,a2,a3))
b1<-c(0.1,2,3.3, 4.5, 6.7)
b2<-c(1.1,2.9,3.4,5.5,7.7)
b3<-c(0.7,2.1,3.8,4.4,5.5)
b<- as.list(data.frame(b1,b2,b3))
df<- mapply(function(X,Y) {
sapply(1:3, function(row) approx(X[row,], Y[row,], xout=seq(0,4, by=1), method="linear"))
}, X=a, Y=b)
What could be the reason for this to happen? Please suggest alternate ideas to bypass this error. Thanks