I have the following code,
z <- data.frame(a=sample.int(10),b=sample.int(10),c=sample.int(10))
letter <- c("a","c","b") # this will be used as the argument to a function
vec <- unlist(lapply(1:length(letter), 
              function(x) cat(paste("z[[letter[",x,"]]],",sep=""))))
vec[length(vec)] <- paste("z[[letter[",length(vec),"]]]",sep="")
Consequently:
> vec    
[1] "z[[letter[1]]]," "z[[letter[2]]]," "z[[letter[3]]]" 
I want to use vec to order the rows of dataframe z, using the code below,
z.sort <- z[with(z, order(???)),]
How can I get the character vector vec to be evaluated as the arguments to order?
Is there a better way of doing this bearing in mind that letter, which is used to form vec will be an argument to a function?
Desired output would be:
    a  b  c
5   1  1  9
10  2 10  2
1   3  7  1
9   4  2  5
8   5  8  6
2   6  4  3
4   7  9 10
3   8  3  8
6   9  5  7
7  10  6  4
or as dput output:
structure(list(a = 1:10, b = c(1L, 10L, 7L, 2L, 8L, 4L, 9L, 3L, 5L, 6L), c = c(9L, 2L, 1L, 5L, 6L, 3L, 10L, 8L, 7L, 4L)), .Names = c("a", "b", "c"), row.names = c(5L, 10L, 1L, 9L, 8L, 2L, 4L, 3L, 6L, 7L), class = "data.frame")