Use data frame in sort function