Displaying 20 results from an estimated 7000 matches similar to: "Sparse matrix performance question"
2004 Aug 31
2
Sparse Matrices in R
I have data in i,j,r format,
where r is the value in location A[i,j] for some imaginary matrix A.
I need to build this matrix A, but given the sizes of i and j, I believe that using a sparse format would be most adequate.
Hopefully this will allow me to perform some basic matrix manipulation such as multiplication, addition, rowsums, transpositions, subsetting etc etc.
Is there any way
2011 Aug 23
0
Matrix:::qr.qy and signature(qr = "sparseQR", y = "dgCMatrix")
> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] Matrix_0.999375-50 lattice_0.19-30
loaded via a namespace (and not attached):
[1] grid_2.13.1
2012 Aug 31
1
using apply with sparse matrix from package Matrix
Hi:
I was trying to use apply on a sparse matrix from package Matrix,
and I get the error:
Error in asMethod(object) :
Cholmod error 'problem too large' at file ../Core/cholmod_dense.c, line 106
Is there a way to apply a function to all the rows without bumping
into this problem?
Here is a simplified example:
> dim(sm)
[1] 72913 43052
> class(sm)
[1] "dgCMatrix"
2011 Dec 31
1
Reading large sparse arff files into R
Hi,
I am trying to read in a large and highly sparse ARFF file into R which was
produced by WEKA. However the package 'RWeka' just chokes on this file. The
data set has about 40k observations and about 20k dimensions. Even after 1hr
read.arff method of RWeka is still trying to read in the file, whereas WEKA
is able to read it in in less than 20seconds.
What are my options at this
2011 Aug 08
1
problem in do.call function
Dear all,
I am trying to use "do.call", but I don't think I totally understand this
function.
Here is an simple example.
--------------------------------------------
> B <- matrix(c(.5,.1,.2,.3),2,2)
> B
[,1] [,2]
[1,] 0.5 0.2
[2,] 0.1 0.3
> x <- c(.1,.2)
> X <- cbind(1,x)
> X
x
[1,] 1 0.1
[2,] 1 0.2
>
> lt <-
2012 Apr 23
0
linear model benchmarking
I cleaned up my old benchmarking code and added checks for missing
data to compare various ways of finding OLS regression coefficients.
I thought I would share this for others. the long and short of it is
that I would recommend
ols.crossprod = function (y, x) {
x <- as.matrix(x)
ok <- (!is.na(y))&(!is.na(rowSums(x)))
y <- y[ok]; x
2005 Apr 21
1
colSums and rowSums with arrays - different classes and dim ?
Hi,
I'm using colSums and rowSums to sum the first dimensions of arrays. It
works ok but the resulting object is different. See
> a3d <- array(rnorm(120, mean=2), dim=c(20,6,1))
> dim(colSums(a3d))
[1] 6 1
> dim(rowSums(a3d))
NULL
> class(colSums(a3d))
[1] "matrix"
> class(rowSums(a3d))
[1] "numeric"
I was expecting rowSums to preserve the array
2009 Nov 30
2
command similar to colSums for rowSums?
Working with an NxMxO sized matrix, currently I can do this in my code:
if (max(colSums(array)) >= number)
But to get an equivalent result using rowSums, I have to do:
for (i in 1:10)
{
if (max(rowSums(array[,,i])) >= number)
}
I'm running both in a much larger loop that loops millions of times, so
speed and such is quite a big factor for me. Currently, the colSums line
uses about
2011 Aug 08
3
on "do.call" function
Dear all,
Even though one of R users answered my question, I cannot understand, so I
re-ask this question.
I am trying to use "do.call", but I don't think I totally understand this
function.
Here is an simple example.
--------------------------------------------
> B <- matrix(c(.5,.1,.2,.3),2,2)
> B
[,1] [,2]
[1,] 0.5 0.2
[2,] 0.1 0.3
> x <- c(.1,.2)
>
2008 Nov 10
1
comparing rows - a possible solution
Hello,
sorry for posting this independently of the original thread, but it is
not that easy to answer to mails, when receiving the r-help as
digest...
...
The question was:
> I compare each row of a matrix with each row of another matrix.
>
> testmat1 <- matrix(c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), nrow=4)
> testmat2 <- matrix(c(1,2,3,5,5,6,7,8,9,10,11,12,13,14,15,16),
2011 May 16
2
conditional rowsums in sapply
Hi all
I have a data frame with duplicate columns and i want to remove duplicates
by adding rows in each group of duplicates, but have lots of NA's.
Data:
dfrm <- data.frame(a = 1:4, b= 1:4, cc= 1:4, dd=1:10, ee=1:4)
names(dfrm) <- c("a", "a", "b", "b", "b")
dfrm[3,2:3]<-NA
dfrm
a a b b b
1 1 1 1 1 1
2 2 2 2 2 2
3
2007 Nov 09
2
rowSums() and is.integer()
Hi
[R-2.6.0, macOSX 10.4.10].
The helppage says that rowSums() and colSums()
are equivalent to 'apply' with 'FUN = sum'.
But I came across this:
> a <- matrix(1:30,5,6)
> is.integer(apply(a,1,sum))
[1] TRUE
> is.integer(rowSums(a))
[1] FALSE
>
so rowSums() returns a float.
Why is this?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre,
2010 Nov 18
2
RowSums Question
I have a question on RowSums.
Lets say i have a timeSeries table
A B C
1/1/90 NA 1 1
1/2/90 NA 1 1
1/3/90 NA 1 1
1/4/90 NA 1 1
1/5/90 1 1 1
1/6/90 1 1 1
if i use RowSums, i will get
1/5/90 3
1/6/90 3
but i want
1/1/90 2
1/2/90 2
1/3/90 2
1/4/90 2
1/5/90 3
1/6/90 3
I cant
2005 Feb 09
4
subset
Dear all,
I am trying to extract rows from a data.frame based on the
rowSums != 0. I want to preserve rownames in the first column in the subset.
Does anyone know how to extract all species that don't have rowSums equal
to zero? Here it is:
# dataset
x <- data.frame(
species=c("sp.1","sp.2","sp.3","sp.4"),
site1=c(2,3,0,0),
site2=c(0,0,0,0),
2007 Mar 24
1
frequency tables and sorting by rowSum
Dear list,
I have some trouble generating a frequency table over a number of vectors.
Creating these tables over simple numbers is no problem with table()
> table(c(1,1,1,3,4,5))
1 3 4 5
3 1 1 1
, but how can i for example turn:
0 1 0
0 0 1
0 1 0
1 0 0
0 1 0
1 0 0
into
0 0 1 1
1 0 0 2
0 1 0 3
My second problem is, sorting rows and columns of a matrix by the rowSums/colSums.
I did it
2011 Mar 29
1
rowsum
> with the entirely different rowSums, but it has been around
> for a long time.)
A lot longer than rowSums ...
> Bill Dunlap
> Spotfire, TIBCO Software
---
This made me smile. The rowsums function was originally an internal
part of the survival package, used for fast computation of certain sums
when there is a cluster() statement. It was Statistical
2018 Mar 21
0
Sum of columns of a data frame equal to NA when all the elements are NA
Should not the result be NULL if you have removed the NA with na.rm=TRUE ?
B.
> On Mar 21, 2018, at 11:44 AM, Stefano Sofia <stefano.sofia at regione.marche.it> wrote:
>
> Dear list users,
> let me ask you this trivial question. I worked on that for a long time, by now.
> Suppose to have a data frame with NAs and to sum some columns with rowSums:
>
> df <-
2008 Sep 24
4
rowSums()
Say I have the following data:
testDat <- data.frame(A = c(1,NA,3), B = c(NA, NA, 3))
> testDat
A B
1 1 NA
2 NA NA
3 3 3
rowsums() with na.rm=TRUE generates the following, which is not desired:
> rowSums(testDat[, c('A', 'B')], na.rm=T)
[1] 1 0 6
rowsums() with na.rm=F generates the following, which is also not
desired:
> rowSums(testDat[, c('A',
2017 Apr 01
0
mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds
From ?NA
Numerical computations using ?NA? will normally result in ?NA?: a
possible exception is where ?NaN? is also involved, in which case
either might result.
and ?NaN
Computations involving ?NaN? will return ?NaN? or perhaps ?NA?:
which of those two is not guaranteed and may depend on the R
platform (since compilers may re-order computations).
2009 May 05
1
Find cyclically identical binary sequences
Dear R-helpers,
I need to generate all the binary sequences of length n (here n = 8)
that start with 1 and have no fewer than two of each digit, and are
not cyclic permutations of each other. Here is what I have done:
len <- 8
df <- as.data.frame(numeric(2^(len - 1)) %o% numeric(len))
require(partitions)
for (i in 1:2^(len - 1)) df[i, ] <- binary(i, dim = len)[[1]]
df <-