Skip to content
Back to formatted view

Raw Message

Message-ID: <8b356f880902130949p33ff0a50n90bcd75abcf22839@mail.gmail.com>
Date: 2009-02-13T17:49:08Z
From: Stavros Macrakis
Subject: Extending each element in a list, or rbind()-ing arrays of 	different length without recycling
In-Reply-To: <1574452236.10732631234469181782.JavaMail.javamailuser@localhost>

Combining the various approaches on the list, here's a simple
one-liner that puts the NAs at the end:

     t(apply(mat,1,function(r) { dr<-duplicated(r); c( r[!dr],
rep(NA,sum(dr)) ) ))

If you don't care where the NAs are, the following is a tad shorter
and perhaps clearer:

     mat[ t(apply(mat,1,duplicated)) ] < -NA                  # modifies mat

         -s