[R] problem accessing complex list data frames
Nick Sabbe
nick.sabbe at ugent.be
Wed Dec 8 13:30:43 CET 2010
Hello Germán.
You probably want something like:
sapply(vmat, function(curMat){
curMat[,999] != 0
})
Or if you want the indices, just surround this with a which.
HTH.
Nick Sabbe
--
ping: nick.sabbe at ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36
-- Do Not Disapprove
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Germán Sanchis
Sent: woensdag 8 december 2010 11:50
To: r-help at r-project.org
Subject: [R] problem accessing complex list data frames
Hi all.
I am currently attempting to build a list of sparse matrixes. That I have
already achieved, by
> vmat <- list()
> for (i in 1:n) {
> vmat <- c(vmat, sparseMatrix(i,j,x=data) }
How I am trying to select those elements from the list where the column e.g.
999 is not null. I can do this for one of the sparse matrices with
> which(vmat[[1]][,999] != 0)
which returns the rows where such column is non-zero.
However, my purpose is to obtain the list indices of the sparse matrices
with such non-zero elements. I tried things like
which(vmat[[]][,999] != 0)
which(vmat[,,999] != 0)
sapply(vmat, which, [,999] != 0)
but none worked... any help will be appreciated!!
Cheers,
German
[[alternative HTML version deleted]]
More information about the R-help
mailing list