[R] c(1:n, 1:(n-1), 1:(n-2), ... , 1)

Dan D ddalthorp at usgs.gov
Thu Sep 17 20:19:05 CEST 2015


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



--
View this message in context: http://r.789695.n4.nabble.com/c-1-n-1-n-1-1-n-2-1-tp4712390.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list