Skip to content
Prev 286482 / 398502 Next

loop for a large database

On Sun, Feb 26, 2012 at 04:13:49AM -0800, mari681 wrote:
Hi.

Try first the following.

  out <- unclass(table(factor(MyTable[[1]], levels=myvector)))

The output should be a table of frequencies of the components
of "myvector" in the first column of "MyTable".

If this works for the data of the size, which you have,
then there are different possible ways how to compute
the frequencies in all columns. For example, concatenate
all columns to a single vector and apply the above to
this concatenation as follows.

  x <- c(as.matrix(MyTable))
  out <- unclass(table(factor(x, levels=myvector))) 

Here, "out" is a vector of the same length as "myvector"
and out[i] is the frequency of myvector[i] in "MyTable".

Hope this helps.

Petr Savicky.