Displaying 20 results from an estimated 9000 matches similar to: "randomly generated binary matrix (with conditions)"
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
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:
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
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,
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
2010 Sep 27
1
stacked area chart
Dear R-ers!
Asking for your help with building the stacked area chart for the
following simple data (several variables - with date on the X axis):
### Creating a data set
my.data<-data.frame(date=c(20080301,20080402,20080503,20090301,20090402,20090503,20100301,20100402,20100503),
x=c(1.1,1.0,1.6,1,2,1.5,2.1,1.3,1.9),y=c(-4,-3,-6,-5,-7,-5.2,-6,-4,-4.9),
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,
2013 Aug 25
3
Rodondeo de una matriz
Gracias, Jorge. Y cual fue la solucion a la que llegaron? --JIV
Sent from my phone. Please excuse my brevity and misspelling.
On Aug 25, 2013, at 8:36 AM, Jorge Ayuso Rejas <jayusor@gmail.com> wrote:
Esto lo hice yo en una práctica en la universidad,
Definíamos un problema de optimización entera minimizando el error de
redondeo y restringiendo a la suma de filas y columnas.
El 23 de
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
2003 Apr 22
4
fisher exact vs. simulated chi-square
Dear All,
I have a problem understanding the difference between the outcome of a
fisher exact test and a chi-square test (with simulated p.value).
For some sample data (see below), fisher reports p=.02337. The normal
chi-square test complains about "approximation may be incorrect",
because there is a column with cells with very small values. I
therefore tried the chi-square with
2007 Nov 14
2
Generating these matrices going backwards
I have generated the following:
x=
E1 E2 E3
D1 0 0 1
D2 1 0 3
D3 0 2 0
y=
E1 E2 E3
D1 0 0 1.75
D2 1.75 0 1.3125
D3 0 3.5 0
Where x and y are linked by:
y =sum(x) * x / (rowSums(x)%o%colSums(x))
N=x[x[1:3,]>0]
R=y[y[1:3,]>0]
Now suppose I ONLY
2010 Oct 04
1
adding a legend to the plot (but outside of it)
Hello!
My code below creates a data frame and a plot for it.
However, I can't figure out how to add a legend that is not ON the
plot itself, but outside of it (e.g., to the right of my graph or
below it). I tried something: I put a line par(xpd=T,
mar=par()$mar+c(0,0,0,4)) right before my plot command), but that
screwed up all my gridlines - they covered all graph and do not
coincide with
2010 Oct 04
1
reducing distances between tickmarks
Hello, everybody!
I have a code below that creates a data set and then a stacked bar
chart based on that data set.
No need to look at it - just notice please that my horizontal axis is
a date varible (x=my.data$date).
I have a question about the last 2 lines of this code:
grid(nx=NULL,ny=NULL,col = "lightgray", lty = "dotted",lwd = par("lwd"))
axis(1, las = 2)
Could
2011 Apr 28
2
Subsetting Data
I'm using the subset() function in R.
dat <- data.frame(one=c(6,7,8,9,10), Number=c(5,15,13,1,13))
subset(dat, Number >= 10)
However, I want to find the number of all rows who meet the Number>=10
condition.
I've done this in the past with something like colSums or rowSums or another
similar function.
But I don't remember how to get the number of elements which meet that
2010 Dec 02
1
Arrange elements on a matrix according to rowSums + short 'apply' Q
Greetings,
My goal is to create a Markov transition matrix (probability of moving from
one state to another) with the 'highest traffic' portion of the matrix
occupying the top-left section. Consider the following sample:
inputData <- c(
c(5, 3, 1, 6, 7),
c(9, 7, 3, 10, 11),
c(1, 2, 3, 4, 5),
c(2, 4, 6, 8, 10),
c(9, 5, 2, 1, 1)
)
MAT <- matrix(inputData,
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 =
2010 Oct 05
2
is there a way to avoid "traveling" grid?
Hello!
If you run the whole code below, it'll produce a stacked diagram. And
it looks good - because the tick-marks are aligned with the grid.
However, if I stretch the graph window, grid becomes misaligned with
the tickmarks. Or, rather, it seems aligned for the first and the last
tick mark, but not for tickmarks in between.
Can it be addressed?
Thank you!
Dimitri
### Creating a data set
2009 Oct 14
1
Beginning R help?
Hi all,
I'm currently working through the "Beginner's Guide to R" (Zurr et al.) and
I'm wondering about the first exercise in chapter 3:
I imported the data from BirdFluCases.txt and executed the 'names' and 'str'
functions as follows:
Bird = read.table(file='C:\\rbook\\BirdFluCases2.txt', header=TRUE)
names(Bird)
[1] "Year"
2006 Nov 10
2
Problems with metaMDS from vegan
Hello all,
I recently used the Vegan library quite extensively (in the context of
text similarity assessment) on an Ubuntu 6.06 LTS system with R version
2.2.1 (2005-12-20 r36812). The Vegan lib is version 1.6-10.
I hit on a problem yesterday, though, when trying to install R and Vegan
on two further computers - one Windows XP and one further Ubuntu 6.06
machine, taking either R version 2.4.0