[R] list to balanced array

From: Spencer Jones <ssj1364_at_gmail.com>
Date: Thu 17 Aug 2006 - 01:22:03 EST


I am working with a large data set of arrivals, for each day I have aggregated the arrivals into hrs (1-24) via: apply(x,2,table). On some days there are zero arrivals during some hours of the day, this leaves me with (I believe) a list of vectors of differnt lengths (see below).

[[4]]

 1 2 3 5 6 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24  1 3 2 3 1 1 2 3 4 4 4 3 2 6 2 5 1 2 2 2 1

[[5]]

2 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 2 1 1 2 1 5 3 6 6 3 2 2 1 4 3 3 4 2 1

 I would like to be able to create an array with equal numbers of rows (24) for each column, i.e., fill in the gaps with Zeros.

[[5]]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 0 2 0 0 1 1 0 2 1 5 3 6 6 3 2 2 1 4 3 0 3 4 2 1

Any suggestions?

thanks,

Spencer

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu Aug 17 01:27:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 17 Aug 2006 - 04:26:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.