search for: rowsum

Displaying 20 results from an estimated 696 matches for "rowsum".

Did you mean: rowsums
2011 Mar 25
2
two minor bugs in rowsum()
(a) In R 2.12.2 rowsum can overflow if given an integer input: > rowsum(c(2e9L, 2e9L), c("a", "a")) [,1] a -294967296 > 2^32 + .Last.value [,1] a 4e+09 Should it be changed to coerce its x argument to numeric (double precision) so it always returns a numeric output? (b) W...
2011 Aug 08
3
on "do.call" function
...> 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 <- expand.grid(i=seq(1,2), y0=seq(0,2)) > lt i y0 1 1 0 2 2 0 3 1 1 4 2 1 5 1 2 6 2 2 > > fc <- function(y0,i) dpois(y0, exp(rowSums(t(X[i,])*B[,1]))) > > do.call(fc,lt) [1] 1.892179e-09 3.348160e-01 3.800543e-08 3.663470e-01 3.816797e-07 2.004237e-01 -------------------------------------------- Unfortunately, what I want to get is dpois(0, exp(rowSums(t(X[1,])*B[,1]))) = 0.1891356 dpois(0, exp(rowSums(t(X[2,])*B[,1]))...
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 1/10th as much time as the rowSums' for loop, and the...
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', 'B')], na.rm=F) [1] NA NA 6 I see...
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] &quot...
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)...
2011 May 16
2
conditional rowsums in sapply
...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 NA NA NA 3 3 4 4 4 4 4 4 I did: sapply(unique(names(dfrm)),function(x){ rowSums(dfrm[ ,grep(x, names(dfrm)),drop=FALSE])}) which works. However, I want rowSums conditional: 1) if there is at least one value non NA in a row of each group of duplicates, apply rowSums to get the value independently of the existence of other NA's in the group row. 2) if all values in a row o...
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 A...
2011 Aug 08
1
problem in do.call function
...gt; 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 <- expand.grid(i=seq(1,2), y0=seq(0,2)) > lt i y0 1 1 0 2 2 0 3 1 1 4 2 1 5 1 2 6 2 2 > > fc <- function(y0,i) dpois(y0, exp(rowSums(t(X[i,])*B[,1]))) > > do.call(fc,lt) [1] 1.892179e-09 3.348160e-01 3.800543e-08 3.663470e-01 3.816797e-07 2.004237e-01 -------------------------------------------- Unfortunately, what I want to get is dpois(0, exp(rowSums(t(X[1,])*B[,1]))) = 0.1891356 dpois(0, exp(rowSums(t(X[2,])*B[,1]...
2011 Nov 22
3
On-demand importing of a package
...I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f <- function() { require(Matrix) res <- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y <- rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around...
2001 Sep 13
1
rowsum dimnames
Hi, The result of rowsum() in R doesn't have the dimnames I'd expect, e.g.: > rowsum(matrix(1:12, 3,4), c("Y","X","Y")) [,1] [,2] [,3] [,4] 1 2 5 8 11 2 4 10 16 22 whereas S-Plus gives the more useful result: [,1] [,2] [,3] [,4] X 2 5 8...
2007 Mar 24
1
frequency tables and sorting by rowSum
...er 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 this way, but i think there should be a more efficient way: sortRowCol<-function(taus) { swaprow <- function(rsum) { taus[(rowSums(taus)==rsum),] } for( i in 1:2 ) taus<-sapply(sort(rowSums(taus)),swaprow) } thanks in advantage, Stefan Nachtnebel -- &q...
2008 Jan 11
2
How to add rowSums into list?
Hi R-users, I have a list a <- list(one=matrix(rnorm(20), 5, 4), two=matrix(rnorm(20, 3, 0.5),5,4)) How to add rowSums (calculated using lapply) to corresponding matrix in this list lapply(a, function(x) rowSums(x)) ?? -Lauri
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...
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...
2001 Sep 14
1
rowsum dimnames (PR#1092)
The result of rowsum() in R doesn't have the dimnames I'd expect, e.g.: > rowsum(matrix(1:12, 3,4), c("Y","X","Y")) [,1] [,2] [,3] [,4] 1 2 5 8 11 2 4 10 16 22 whereas S-Plus gives the more useful result: [,1] [,2] [,3] [,4] X 2 5 8...
2016 Sep 15
2
row names of 'rowsum()'
'rowsum()' seems to add row names to the resulting matrix, corresponding to the respective 'group' values. This is very handy, but it is not documented. Should the documentation mention it so it could be relied upon as part of API? Cheers, Ott -- Ott Toomet Visiting Researcher School of I...
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: http://r.789695.n4.nabble.com/how-to-divide-each-column-in-a-matrix-by-its-colSums-tp3062739p3062739.html...
2006 Nov 21
2
using nested ifelse and rowSums to create new variable?
...ifelse. I then want to assign a value to the new variable based upon the count. The new variable I want to create is called dep. Here's my R code: dep<-with(df, ifelse((x1==5) & (x2==5), 0, ifelse((x1==1 & x2==1), 1, ifelse((x1==1 & x2==5) | (x1==5 & x2==1) & (rowSums(df[ ,c(x3, x4, x5, x6)]<4) ==1), 2, ifelse((x1==1 & x2==5) | (x1==5 & x2==1) & (rowSums(df[ ,c(x3, x4, x5, x6)]<4) ==2), 3, ifelse((x1==1 & x2==5) | (x1==5 & x2==1) & (rowSums(df[ ,c(x3, x4, x5, x6)]<4) ==3), 4, 99)))))) dep 0 1 2 99 6 3 6 5 I exp...
2008 Mar 25
2
help with rowsum/aggregate type functions
...9 1174 Zeb2 6 What I want is to collapse the list by gene name, such that duplicates are summed up and appear only once in the final version: Zcchc8 6 Zcwpw1 5 Zdhhc18 6 Zdhhc20 5 Zdhhc3 11 Zeb2 15 The only way I can figure out to do this is via rowsum: > rowsum (Number,Gene_Name) gives me exactly what I want, *except* that in the end, I am left with a matrix containing the Number values and with the Gene_Names used as row names (the output therefore looks exactly as printed above) -- what I want is a dataframe equivalent to the starting...