I'm having an issue using *apply* functions (which I assume is the right way to do the following) across multiple data frames. 

Some example data (3 different data frames, but the problem I'm working on has upwards of 50):

```
biz <- data.frame(
    country = c("england","canada","australia","usa"),
    businesses = sample(1000:2500,4))

pop <- data.frame(
    country = c("england","canada","australia","usa"),
    population = sample(10000:20000,4))

restaurants <- data.frame(
    country = c("england","canada","australia","usa"),
    restaurants = sample(500:1000,4))

```

Here's what I ultimately want to do:

1) Sort eat data frame from largest to smallest, according to the variable that's included

```
dataframe <- dataframe[order(dataframe$VARIABLE,)]

```

2) then create a vector variable that gives me the rank for each

```
dataframe$rank <- 1:nrow(dataframe)

```

3) Then create another data frame that has one column of the countries and the rank for each of the variables of interest as other columns. Something that would look like (rankings aren't real here):

```
country.rankings <- structure(list(country = structure(c(5L, 1L, 6L, 2L, 3L, 4L), .Label = c("brazil", 
"canada", "england", "france", "ghana", "usa"), class = "factor"), 
    restaurants = 1:6, businesses = c(4L, 5L, 6L, 3L, 2L, 1L), 
    population = c(4L, 6L, 3L, 2L, 5L, 1L)), .Names = c("country", 
"restaurants", "businesses", "population"), class = "data.frame", row.names = c(NA, 
-6L))

```

So I'm guessing there's a way to put each of these data frames together into a list, something like:

```
lib <- c(biz, pop, restaurants)

```

And then do an *lapply* across that to 1) sort, 2)create the rank variable and 3) create the matrix or data frame of rankings for each variable (# of businesses, population size, # of restaurants) for each country. Problem I'm running into is that writing the *lapply* function to sort each data frame runs into issues when I try to order by the variable:

```
sort <- lapply(lib, 
    function(x){
        x <- x[order(x[,2]),]
        })

```

returns the error message:

```
Error in `[.default`(x, , 2) : incorrect number of dimensions

```

because I'm trying to apply column headings to a list. But how else would I tackle this problem when the variable names are different for every data frame (but keeping in mind that the country names are consistent)

(would also love to know how to use this using *plyr*)