HI! I?ve 3 vectors of different length (a,b,c) and want to arrange them in a matrix a,b,c as rows and the figures of these vectors in the columns (with that matrix i want to calculate a distance between thes vectors - vegan - vegdist - horn). Is there a possibilty to create such a matrix and to fill up the missing fields with NA?s automatically???? Thanx marten winter -- *Marten Winter* ___________________________________________________________________________________________________________________________________ UFZ - Umweltforschungszentrum Leipzig-Halle GmbH Sektion Biozoenoseforschung Theodor-Lieser-Stra佭e 4 D-06120 Halle (Saale) Centre for Environmental Research (UFZ) Leipzig-Halle Department of Community Ecology Theodor-Lieser-Str. 4 D-06120 Halle (Saale) Germany phone: ++49 (0) 345 558-5316 fax:++49 (0) 345 558-5329 E-mail: Marten.Winter@ufz.de <mailto:Marten.Winter@ufz.de> http://www.halle.ufz.de/bzf/ ___________________________________________________________________________________________________________________________________ [[alternative HTML version deleted]]
On 8/22/2005 8:45 AM, Marten Winter wrote:> HI! > > I?ve 3 vectors of different length (a,b,c) and want to arrange them in a > matrix a,b,c as rows and the figures of these vectors in the columns > (with that matrix i want to calculate a distance between thes vectors - > vegan - vegdist - horn). Is there a possibilty to create such a matrix > and to fill up the missing fields with NA?s automatically????Filling with NA's is the hard part; R normally likes to recycle vectors that are too short. Here's one way, probably not the best: x <- matrix(NA, 3, max(length(a), length(b), length(c))) x[1,seq(along=a)] <- a x[2,seq(along=b)] <- b x[3,seq(along=c)] <- c Another way to do it would be to extend all the vectors to the same length by appending NAs, then using rbind. Duncan Murdoch