It's not clear to me why you would want to do this, but here's one way to independently sort each column of a data frame and fit a lowess smooth to it:
i <- iris[, 1:4]
k <- apply(i, 2, function(x) lowess(x[order(x)], f=1/10)[[2]][match(x, x[order(x)])])
Using the double brackets, [[2]]
, ensures that the result, k
, is a matrix rather than a list. Although this approach fits a lowess smooth to each column sorted independently, in order to keep the results in the same order as the original data frame i
, you need to "unsort" it. That's what the [match(...)]
part of the code is doing.