Skip to content
Prev 170332 / 398506 Next

Extending each element in a list, or rbind()-ing arrays of different length without recycling

At the risk of beating the decaying skeletal remains of the stone dead
horse, a one-liner:

t(apply(mat,1,function(x)c(unique(x),rep(NA,sum(duplicated(x))))))

(probably more efficient as a 2-liner that calls duplicated/unique only
once, though)

-- Bert Gunter, Genentech

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of markleeds at verizon.net
Sent: Thursday, February 12, 2009 1:05 PM
To: Rolf Turner
Cc: r-help at r-project.org; Jason Shaw
Subject: Re: [R] Extending each element in a list, or rbind()-ing arrays of
different length without recycling

  Thanks Rolf. very nice but "pretty easy" is ALWAYS a relative 
statement.
On Thu, Feb 12, 2009 at 3:59 PM, Rolf Turner wrote:

            
______________________________________________
R-help at r-project.org 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.