[R] How to manipulate tables

James Rome jamesrome at gmail.com
Sat Dec 26 20:02:50 CET 2009


I am sorry to be bothering the list so much.

I made a table of counts of flight arrivals by hour:
cnts=tapply(Arrival4,list(Hour),table). There are up to 15 arrivals in a
bin.
> cnts
$`0`

 1  2  3  4  5  6  7  8  9 10 13
 1  2  5  9  2  7  5  4  2  4  1

$`1`

1 2 3 4
3 2 2 1

$`2`

1 3
2 2
.  . .

My first problem is how to get this table filled in with the 0 slots.
E.g., I want
$`0`

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
 1  2  5  9  2  7  5  4  2  4   0   0   1   0   0

for all 24 hours. The elements of the tables are lists, but I do not
seem to be able to extract the names of each list, which I think would
allow this manipulation.

My second problem is that I want to compute probability distributions. I
have
lambda
          0           1           2           4           5          
6           7
0.199190283 0.013765182 0.006477733 0.017813765 0.093117409 0.160323887
0.401619433
          8           9          10          11          12         
13          14
0.191093117 0.177327935 0.318218623 0.404858300 0.463157895 0.495546559
0.435627530
         15          16          17          18          19         
20          21
0.418623482 0.307692308 0.405668016 0.484210526 0.580566802 0.585425101
0.519028340
         22          23
0.556275304 0.503643725

and I need to calculate lambda**cnts for each bin, and each hour. I am
also unsure of how to do this.

Thanks in advance kind people on this list
Jim Rome




More information about the R-help mailing list