Thank you Dimitris, that solves it exactly! I continue to be amazed at how
a single line of code can be so powerful in R, containing so much
information. Hard as hell to interpret though (for me).
Jim
> one approach is the following:
>
> B <- cbind(c(1:6, NA), c(1:3, NA,NA,NA, 4), c(1:3, NA,NA
one approach is the following:
B <- cbind(c(1:6, NA), c(1:3, NA,NA,NA, 4), c(1:3, NA,NA, 4,5))
matrix(B[order(col(B), B)], nrow(B), ncol(B))
I hope it helps.
Best,
Dimitris
Jim Bouldin wrote:
And think about the fact that row(A) and apply(is.na(A), 2, cumsum)
will be identical in the case
> And think about the fact that row(A) and apply(is.na(A), 2, cumsum)
> will be identical in the case where there are no NAs, so their
> difference would be a zero matrix. Double negativism strikes again
> not(is.na) == "is"
OK I see it now--thanks. I was interpreting the apply functio
On Nov 22, 2009, at 11:11 AM, Jim Bouldin wrote:
Many thanks to Dimitris, William and David for very helpful answers
which
solved my problem. Being a relatve newb, I am confused by something
in the
solutions by Dimitris and David.
#Create a matrix A as follows:
A <- matrix(sample(50,
Many thanks to Dimitris, William and David for very helpful answers which
solved my problem. Being a relatve newb, I am confused by something in the
solutions by Dimitris and David.
#Create a matrix A as follows:
> A <- matrix(sample(50, 21), 7, 3)
> A[sample(21, 5)] <- NA;A
[,1] [,2] [,3
Thank you and apologies--I did not make it clear that there are no NAs
mixed in with the valid values. Rather, they all occur consecutively,
either toward the beginning of end of the column.
Jim
> I didn't know what you wanted to do if there were NA's
> in the middle of a column.
>
> Bill Dunla
On Nov 21, 2009, at 3:25 PM, William Dunlap wrote:
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Jim Bouldin
Sent: Saturday, November 21, 2009 10:34 AM
To: r-help@r-project.org
Subject: [R] consecutive numbering of elements in
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Bouldin
> Sent: Saturday, November 21, 2009 10:34 AM
> To: r-help@r-project.org
> Subject: [R] consecutive numbering of elements in a matrix
>
>
if I understand what you want correctly, then one approach is:
A <- matrix(sample(50, 21), 7, 3)
A[sample(21, 5)] <- NA
A
row(A) - apply(is.na(A), 2, cumsum)
I hope it helps.
Best,
Dimitris
Jim Bouldin wrote:
Within a very large matrix composed of a mix of values and NAs, e.g, matrix A:
Within a very large matrix composed of a mix of values and NAs, e.g, matrix A:
[,1] [,2] [,3]
[1,]1 NA NA
[2,]3 NA NA
[3,]3 10 17
[4,]4 12 18
[5,]6 16 19
[6,]6 22 20
[7,]5 11 NA
I need to be able to consecutively number, in new columns
10 matches
Mail list logo