Vivek Subramanian - 6 months ago 44

R Question

I'm trying to count the number of occurrences in many vectors and store them in a matrix in R. For example, I'd like entries in the matrix

`a`

`a[[1]]`

`a[[2]]`

`table(factor(x, levels=7:9))`

`x`

`a[[10]]`

`[3 3 1]`

`x`

`a`

`[1 0 1]`

`a[[10]]`

`[4 3 2]`

`x`

`a[[10]]`

Answer

I did this simply by preceding my code with a check for if `a[[i]]`

is `null`

. If so, then I did `a[[i]] = table(factor(0, levels=7:9))`

.