My R function does the following:
- reads in the directory name 
 
- reads a particular set of numbers that represents the files
 
- combines the mentioned files into a data frame
 
- prints out the number of occurrences for a particular ID
 
Here's the function:
library(plyr)
complete <- function(directory, id=1:5){
  files_full <- list.files(directory, full.names=TRUE)
  working_set <- files_full [id]
  seethis <- lapply(working_set, read.csv)
  output <- do.call(rbind, seethis)
  no_na <- na.omit(output)
  new_df <- as.data.frame(no_na)
  new_output <- count(new_df,"ID")
  colnames(new_output) <- c("id", "Occurrences")
  new_output
}
Now, If the function is invoked with
complete("diet_data",c(4,3,2))
I get the following:
  id Occurrences
1  2          30
2  3          17
3  4          30
But I wish to retain the id order, i.e. 4, 3, 2 so that output is
  id Occurrences
1  4          30
2  3          17
3  2          30
How to do this? And there is no way to tell if id will be 1:5, 5:3, etc