I am trying to use "rbind" to get the result but I am being shown an error "Error in rbind(deparse.level, ...) : invalid list argument: all variables should have the same length"
pm2 <- function(directory, id=1:322)
{
  files  <- list.files(path = directory, full.names = TRUE)
  df <- data.frame()
  for (i in 1:322)
  {
        fil <- read.csv(files[i])
        df <- rbind(df, fil)
  }
  df2 <- data.frame(matrix(nrow = length(id), ncol = 2))
  colnames(df2) <- c("id", "nobs")
  for(i in id){
        rbind(df2, c(df[[id[i]]],count((df[[id[i]]])),na.rm = TRUE)) 
  }
  df2
}
pm2("specdata", 1:10)
 
    