[R] another matrix problem

William Simpson william.a.simpson at gmail.com
Sun Jul 5 17:57:28 CEST 2009


Thanks very much Gabor

Bill

On Sun, Jul 5, 2009 at 4:44 PM, Gabor
Grothendieck<ggrothendieck at gmail.com> wrote:
> In terms of x this is:
>
> k <- 3
> x <- 1:5
>
> n <- length(x)
> matrix(x, 2*n-1, k)[1:n, ]
>
> On Sun, Jul 5, 2009 at 10:01 AM, Gabor
> Grothendieck<ggrothendieck at gmail.com> wrote:
>> Try this (ignore the warning):
>>
>> k <- 3
>> matrix(1:5, 9, k)[1:5, ]
>>
>>
>> On Sun, Jul 5, 2009 at 8:54 AM, William
>> Simpson<william.a.simpson at gmail.com> wrote:
>>> I want a function that takes an input vector, the number of columns
>>> and returns a matrix as follows.
>>>
>>> x<- 1:5
>>>
>>> foo(x, nc=3)
>>>
>>> 1 5 4
>>> 2 1 5
>>> 3 2 1
>>> 4 3 2
>>> 5 4 3
>>>
>>> Thanks again for any help.
>>>
>>> Bill
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>




More information about the R-help mailing list