replace 0 with NA and then back again:
> f
function(a){cbind(a,a+1,rev(a)
)}
> f(1:5)
a
[1,] 1 2 5
[2,] 2 3 4
[3,] 3 4 3
[4,] 4 5 2
[5,] 5 6 1
> x <- c(1,0,3,4,0,5)
> f(x)
a
[1,] 1 2 5
[2,] 0 1 0
[3,] 3 4 4
[4,] 4 5 3
[5,] 0 1 0
[6,] 5 6 1
> x[x==0] <- NA
> f(x)
a
[1,] 1 2 5
[2,
000
> [3,]000
> [4,]234
> [5,]452
> [6,]000
> [7,]341
>
> -Christos
>
> -Original Message-
> From: Robin Hankin [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 27, 2006 10:16 AM
> To:
00
[7,]341
-Christos
-Original Message-
From: Robin Hankin [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 27, 2006 10:16 AM
To: [EMAIL PROTECTED]
Cc: 'Robin Hankin'; 'RHelp'
Subject: Re: [R] inserting rows into a matrix
Hi Christos
thanks for this, but it won
Try this where f and A2 are as in your post:
out <-f(A2[A2>0])
replace(matrix(0, length(A2), ncol(out)), A2 > 0, out)
On 7/27/06, Robin Hankin <[EMAIL PROTECTED]> wrote:
> Hi
>
>
> I have a little vector function that takes a vector A of strictly
> positive integers
> and outputs a matrix
m: Robin Hankin <[EMAIL PROTECTED]>
>To: RHelp
>Subject: [R] inserting rows into a matrix
>Date: Thu, 27 Jul 2006 14:54:02 +0100
>
>Hi
>
>
>I have a little vector function that takes a vector A of strictly
>positive integers
>and outputs a matrix M each
f Robin Hankin
> Sent: Thursday, July 27, 2006 9:54 AM
> To: RHelp
> Subject: [R] inserting rows into a matrix
>
> Hi
>
>
> I have a little vector function that takes a vector A of strictly
> positive
> integers and outputs a matrix M each of whose columns is the
mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
Sent: Thursday, July 27, 2006 9:54 AM
To: RHelp
Subject: [R] inserting rows into a matrix
Hi
I have a little vector function that takes a vector A of strictly positive
integers and outputs a matrix M each of whose columns is the vector,
modifie
Hi
I have a little vector function that takes a vector A of strictly
positive integers
and outputs a matrix M each of whose columns is the vector, modified in
a complicated combinatorical way.
Now I want to generalize the function so that A can include zeroes.
Given A,
I want to strip out