Skip to content

vectors of different length in a matrix

4 messages · Marten Winter, Duncan Murdoch, Jari Oksanen

#
On 8/22/2005 8:45 AM, Marten Winter wrote:
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
#
On Mon, 2005-08-22 at 08:56 -0400, Duncan Murdoch wrote:
Another issue is that this would fail at the next step outlined in the
original message ("vegan - vegdist - horn"), since that step won't
accept NAs. So the original schedule was bad. If you fill with zeros,
then the 'vegdist' step would work in the sense that it produces
numbers. I don't know if these numbers would make any sense if the
vectors had nothing to do with each other originally, and columns would
be of mixed meaning after stacking into a matrix. If your vector
elements had identities ("names") originally, then you should stack your
data so that entries with the same identity go to the same column. It is
difficult to imagine Horn index used in cases where you don't have these
identities -- specifically species names.  

cheers, jari oksanen
#
On Mon, 2005-08-22 at 16:13 +0300, Jari Oksanen wrote:
Uh. It seems that I should read the package documentation (and posting
guide which tells me to do so): it seems that vegdist() *can* handle
NAs. I do still think that data with NA probably makes no sense with
alternative "horn".

cheers, jari oksanen