frequency on multi variables I'm looking for an efficient way in R to get a frequency table on multiple variables (in my case 180 variables) with same range of (ordinal)scores.
Example:
from this:
id  v1  v2  v3
1   36  35  35
2   37  37  36
3   37  37  36
4   35  36  36
5   36  36  36
6   35  35  34
7   36  36  35
8   37  37  37
9   36  36  36
10  37  38  38

into this:
value   v1  v2  v3
34  0   0   1
35  2   2   2
36  4   4   5
37  4   3   1
38  0   1   1

There are many ways within R for frequency tables but haven't encountered yet an solution to this.
Many thanks in advance for your suggestions!
P.S.: Here is the code to reproduce the example:
df <- data.frame(id = 1:10,
                 v1 = c(36, 37, 37, 35, 36, 35, 36, 37, 36, 37),
                 v2 = c(35, 37, 37, 36, 36, 35, 36, 37, 36, 38),
                 v3 = c(35, 36, 36, 36, 36, 34, 35, 37, 36, 38))

 A: Not the prettiest way, but it gets the job done.
We start by reproducing your data (id omitted for irrelevance):
df <- data.frame(v1 = c(36, 37, 37, 35, 36, 35, 36, 37, 36, 37),
                 v2 = c(35, 37, 37, 36, 36, 35, 36, 37, 36, 38),
                 v3 = c(35, 36, 36, 36, 36, 34, 35, 37, 36, 38))

The we use sapply to generate tables for all the variables:
tab.list <- sapply(df, table)

The mess below formats the list of tables above the way you wanted:
tab.list <- lapply(tab.list, data.frame)  # reformat tables as dataframes

# These two lines use Reduce() to apply merge() multiple times
adhoc.merge <- function(...) merge(..., by = "Var1", all = TRUE)
tab.df      <- Reduce(adhoc.merge, tab.list)

names(tab.df)         <- c("value", "v1", "v2", "v3")  # rename variables
tab.df[is.na(tab.df)] <- 0                             # replace NAs with 0

# These last two lines reorder the dataset
tab.df$value  <- factor(tab.df$value, levels = range(df)[1]:range(df)[2])
tab.df        <- tab.df[order(tab.df$value), ]

The final result:
> tab.df
  value v1 v2 v3
5    34  0  0  1
1    35  2  2  2
2    36  4  4  5
3    37  4  3  1
4    38  0  1  1

