Displaying 20 results from an estimated 10000 matches similar to: "logical masking of a matrix converts it to a vector"
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
2003 Sep 14
1
Documentation of colSums et. al (PR#4154)
Full_Name: Doug Grove
Version: 1.7.0
OS: Linux
Submission from: (NULL) (209.31.211.56)
Hi,
Minor mistake in the documentation on the colSums page.
In the ARGUMENTS section it states for 'dims' that:
For `col*', the sum or mean is over dimensions
`dims+1, ...'; for `row*' it is over dimensions `1:dims'.
These two are reversed.
Thanks,
Doug Grove
2017 Oct 21
1
What exactly is an dgCMatrix-class. There are so many attributes.
> On Oct 21, 2017, at 7:50 AM, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>
>>>>>> C W <tmrsg11 at gmail.com>
>>>>>> on Fri, 20 Oct 2017 15:51:16 -0400 writes:
>
>> Thank you for your responses. I guess I don't feel
>> alone. I don't find the documentation go into any detail.
>
>> I also find
2008 Mar 07
4
Warning: matrix by vector division
Dear list,
I just made a very simple mistake, but it was hard to spot. And I
think that I should warn other people, because it is probably so
simple to make...
=== R code ===
# Let us create a matrix:
(a <- cbind(c(0,1,1), rep(1,3)))
# [,1] [,2]
# [1,] 0 1
# [2,] 1 1
# [3,] 1 1
# That is a MISTAKE:
a/colSums(a)
# [,1] [,2]
# [1,] 0.0000000 0.3333333
2007 Jan 26
2
%*% in Matrix objects
Dear R users,
I need to normalize a bunch of row vectors. At a certain point I need to divide a matrix by a vector of norms. I find that the behavior of Matrix objects differs from normal matrix objects. Example the following code examples differ only in xnormed changing from normal to Matrix object:
x = matrix(1:12,3,4)
x = as(x, "CsparseMatrix")
xnorms = sqrt(colSums(x^2))
2010 Oct 01
2
How to apply vector value function to a multidimensional array indexed by the remaining dimensions?
Hi,
I am looking for some generalization of colSums and rowSums for general
vector valued functions, and for arrays of more than 2 dimensions.
So as a concrete example, suppose I have a 3 dimensional array, given by x
= array(1:100,c(3,4,5)).
and I want to sum the 3rd index of x to obain a 3 by 4 matrix. Using rowSums
would return a vector of length 3 because it treats the last two indices as
2013 Jul 04
2
porcentajes
Buenos días
quiero definir situación_2 <-tapply(ICE_3$FACTOR_CORR, list(X.1.1Eneltrimestrequeestáacabando=ICE_3$X.1.1Eneltrimestrequeestáacabando, CNAE_1=ICE_3$CNAE_1), f) donde f sea el porcentaje por filas (y/o el porcentaje por columnas) y las funciones rowPercent y colPercent me dan el siguiente error
Error en tapply(ICE_3$FACTOR_CORR, list(X.1.1Eneltrimestrequeestáacabando =
2013 Jan 27
2
Loops
Dear Contributors,
I am asking help on the way how to solve a problem related to loops for
that I always get confused with.
I would like to perform the following procedure in a compact way.
Consider that p is a matrix composed of 100 rows and three columns. I need
to calculate the sum over some rows of each
column separately, as follows:
fa1<-(colSums(p[1:25,]))
fa2<-(colSums(p[26:50,]))
2010 Nov 28
4
how to divide each column in a matrix by its colSums?
Hi,
I have a matrix, say
m=matrix(c(
983,679,134,
383,416,84,
2892,2625,570
),nrow=3
)
i can find its row/col sum by
rowSums(m)
colSums(m)
How do I divide each row/column by its rowSum/colSums and still return in
the matrix form?
(i.e. the new rowSums/colSums =1)
Thanks.
Casper
--
View this message in context:
2010 Dec 26
1
T2 hoteling
Dear All
It is very kind of you to guide me.
When I want to run this line, I see this error
stat.obs <- apply(GS, 2, function(z) Hott2(t(DATA[which(z==1),]), cl))
Error in colSums(w * x) : 'x' must be an array of at least two dimensions
cl <- as.factor(y)
GS: a matrix with 0 or 1
GS: gene sets
-> a data matrix with rows=genes,
columns= gene sets,
GS[i,j]=1 if gene i in
2017 Oct 21
0
What exactly is an dgCMatrix-class. There are so many attributes.
>>>>> C W <tmrsg11 at gmail.com>
>>>>> on Fri, 20 Oct 2017 15:51:16 -0400 writes:
> Thank you for your responses. I guess I don't feel
> alone. I don't find the documentation go into any detail.
> I also find it surprising that,
>> object.size(train$data)
> 1730904 bytes
>>
2008 Nov 14
1
# values used in a function in tapply
Hello,
I am using tapply to pull out data by the day of week and then perform
functions (e.g. mean). I would like to have the number of values used for
the calcuation for the functions, sorted by each day of week. A number of
entries in any given column are NAs.
I have tried the following code and simple variants with no luck.
for (i in 1:length(a[1,])){
x<-tapply(a[,i],a[,1],mean,
2001 Dec 14
2
colSums in C
Hi, all!
My project today is to write a speedy colSums(), which is a function
available in S-Plus to add the columns of a matrix. Here are 4 ways to do it,
with the time it took (elapsed, best of 3 trials) in both R and S-Plus:
m <- matrix(1, 400, 40000)
x1 <- apply(m, 2, sum) ## R=16.55 S=52.39
x2 <- as.vector(rep(1,nrow(m)) %*% m) ## R= 2.39 S= 8.52
x3 <-
2013 Jul 22
1
union of a list of logical values
Dear all,
How can I obtain the union of a list of logical values?
Consider the following:
x <- head(iris)
x[,c(2,4)] <- NA
x[c(2,4),] <- NA
# > x
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1 5.1 NA 1.4 NA setosa
# 2 NA NA NA NA <NA>
# 3 4.7 NA 1.3
2007 Apr 16
1
colSum() in Matrix objects
Hi,
I'd like to simply add column-wise using Matrix objects (Csparse).
It looks like one can apply mosty any base function to these objects
(i.e., apply, colSums), but there is a nasty conversion to traditional
matrix objects if one does that.
Is there any workaround? I can see colSum listed in the help for Class
'CsparseMatrix' , but I wonder whether I'm using the default
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
2013 Aug 23
2
Rodondeo de una matriz
Buenas tardes a tod@s,
Me gustaria redondear las entradas de una matriz m manteniendo la suma de
filas y columnas constantes (son valores fijos conocidos). En la
aplicacion que estoy trabajando (en la que por supuesto m tiene una
dimension mayor que en el ejemplo), no son permitidos numeros decimales y
por ello debe efectuarse el redondeo.
La forma de m es:
m <- matrix(c(3.546, 4.5345,
2009 Jan 28
3
for/if loop
Hi, it's my first time to write a loop with R for my homework. This loop is
part of the function. I wanna assign values for hll according to panel
[ii,1]=pp. I didn't get any error message in this part. but then when I
further calculate another stuff with hll, the function can't return. I think
it must be some problem in my loop. Probably something stupid or easy. But I
tried to look
2011 Jun 03
1
function to reduce resolution of a vector or matrix?
Hi,
I feel dumb even asking, but isn't there an R function somewhere that I
can use to reduce the resolution of a vector (or matrix) by summing
terms in uniform blocks? That is, for a vector X, reduce it to some
X.short as X.short[1]<- sum(X[1:10]); X.short[2] <- sum(X[11:20]), and
so on.
I did the following:
X.short<-colSums(matrix(X,16,2048/16)) # X is of length 2048
but
2006 Dec 01
3
Make many barplot into one plot
Dear all,
## I have 4 tables like this:
satu <- array(c(5,15,20,68,29,54,84,119), dim=c(2,4),
dimnames=list(c("Negative", "Positive"), c("Black",
"Brown", "Red", "Blond")))
dua <- array(c(50,105,30,8,29,25,84,9), dim=c(2,4),
dimnames=list(c("Negative", "Positive"),