Hi all,
I have following ch. matrix :
mat
[,1][,2] [,3][,4]
[1,] NA0.0671746073115122 1.15281464953731
0.822277316923348
[2,] 0.113184828073156 -0.0133150789005112 0.640912657072027
-0.0667317787225847
On Sep 16, 2009, at 9:40 AM, Bogaso wrote:
Hi all,
I have following ch. matrix :
mat
[,1][,2] [,3][,4]
[1,] NA0.0671746073115122 1.15281464953731
0.822277316923348
[2,] 0.113184828073156 -0.0133150789005112
On 16-Sep-09 13:40:03, Bogaso wrote:
Hi all,
I have following ch. matrix :
mat
[,1][,2] [,3][,4]
[1,] NA0.0671746073115122 1.15281464953731
0.822277316923348
[2,] 0.113184828073156 -0.0133150789005112
rotateleft-function(vec,offset)
vec[(((0:(length(vec)-1))+offset) %% length(vec)) + 1]
rotateright-function(vec,offset)rotateleft(vec,length(vec)-offset)
rotatedcols-
function
(vec
,offsets)do.call(cbind,lapply(offsets,function(x)rotateright(vec,x)))
rotatedcols(1:5,0:2)
is perhaps what
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@r-project.org mailing list
On Jul 5, 2009, at 8:54 AM, William Simpson 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
See if this gives you any ideas:
sapply(1:3, function(z) { ((x - z) %% 5) +1 } )
Try this (ignore the warning):
k - 3
matrix(1:5, 9, k)[1:5, ]
On Sun, Jul 5, 2009 at 8:54 AM, William
Simpsonwilliam.a.simp...@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
Try this:
foo - function(x, ncols){
tail(embed(rep(x, ncols), ncols), length(x))
}
foo(x, 3)
On Sun, Jul 5, 2009 at 9:54 AM, William Simpson william.a.simp...@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
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
Grothendieckggrothendi...@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
Thanks very much Gabor
Bill
On Sun, Jul 5, 2009 at 4:44 PM, Gabor
Grothendieckggrothendi...@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
Grothendieckggrothendi...@gmail.com wrote:
Try this (ignore
Hi
Not sure what you want to do.
You can set dimensions to your vector.
vec-1:12
dim(vec)-c(3,4)
you can repeat your vector for n times
vec-rep(1:4,3)
dim(vec) - c(4,3)
or you can use byrow option
vec-1:12
matrix(vec, nrow=4, ncol=3, byrow=T)
Petr Pikal
[EMAIL PROTECTED]
724008364,
11 matches
Mail list logo