Note that:

>> Also not sure about efficiency but somewhat shorter...
>> unlist(lapply(5:1, seq))
>>
>>> Peter
>>>

is almost exactly sequence(5:1)

which is

unlist(lapply(5:1,seq_len))

which is "must preferred". See ?seq for details

Cheers,
Bert



>>> On Thu, Sep 17, 2015 at 11:19 AM, Dan D <ddalth...@usgs.gov> wrote:
>>>> Can anyone think of a slick way to create an array that looks like c(1:n,
>>>> 1:(n-1), 1:(n-2), ... , 1)?
>>>>
>>>> The following works, but it's inefficient and a little hard to follow:
>>>> n<-5
>>>> junk<-array(1:n,dim=c(n,n))
>>>> junk[((lower.tri(t(junk),diag=T)))[n:1,]]
>>>>
>>>> Any help would be greatly appreciated!
>>>>
>>>> -Dan
>>>>
>>>>
>
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to