Displaying 20 results from an estimated 7000 matches similar to: "rowsum"
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) When rowsum is given an x containing both NaN and NA it
appears to use the last
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
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 11
Y 4 10 16 22
This is because R's rowsum() code gives
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 11
Y 4 10 16 22
This is because R's rowsum() code gives the
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 Information
Mary Gates Hall, Suite 310
University of Washington
Seattle, WA 98195
2012 Jun 05
3
rowSums problem
I'm having a very frustrating problem, trying to find the inverse distance
squared weighted interpolants of some weather data.
I have a data frame of weights, which sum to 1. I have attached the weights
data. I also have a data frame of temperatures at 48 grid points, which I
have also attached.
Now, all I need to do is multiply all of the rows of the temperature data
frame by the weights
2003 Aug 13
2
rowsum() may return a vector instead of a matrix (PR#3737)
If all rows are in the same "group", rowsum() returns a vector instead of a
(1xN) matrix, contrary to documentation:
R> print(z <- rowsum(matrix(1:12, 3,4), rep("x",3)))
[1] 6 15 24 33
R> dim(z)
NULL
It worked correctly in version 1.4.0 but was broken by version 1.6.1. I'm
currently using 1.7.1 under Solaris 2.8.
--please do not edit the information
2008 Mar 25
2
help with rowsum/aggregate type functions
Hi--
This is a question with a trivial and obvious answer, I'm sure, but I can't seem to find it in the help files and books that I have handy. I have a dataframe consisting of two columns, "Gene_Name," a list of gene symbols, and "Number," a numeric measure of how frequently a tag representing that gene showed up in a SAGE library. Several of the genes are
2013 Feb 06
1
weighing proportion of rowSums in dataframe
Dear R-List,
I am sure there must be a very simple way to do this - I just do not know how...
This is what I want to do:
#my dataframe
df<-data.frame(id=c("x01","x02","x03","x04","x05","x06"),a=c(1,2,NA,4,5,6),b=c(2,4,6,8,10,NA),c=c(NA,3,9,12,NA,NA),sum=c(3,9,15,24,15,6))
id a b c sum
1 x01 1 2 NA 3
2
2011 Mar 07
2
rowSums - am I getting something wrong?
I am trying to construct a data set with some sequences for example:
a = seq(0,1,0.1)
m = matrix(nrow = 1331, ncol = 3)
m[,1] = rep(a,121)
m[,2] = rep(a,11,each = 11)
m[,3] = rep(a,1,each = 121)
I realize that there may be better ways of doing this, but this approach demonstrates the problem I'm having.
I then want to get the sum of the rows and delete any row with a sum of greater than 1.
2011 Jul 15
1
Confusing inheritance problem
I have library in development with a function that works when called
from the top level, but fails under R CMD check. The paricular line of
failure is
rsum <- rowSums(kmat>0)
where kmat is a dsCMatrix object.
I'm currently stumped and looking for some ideas.
I've created a stripped down library "ktest" that has only 3
functions: pedigree.R to create a pedigree or
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 Oct 20
2
rowsum
Hello,
I am trying to achieve something which I *think* is possible using rowsum,
but a little help should be useful:
Consider the following dataframe DF0:
A B C
89 1 140
89 06 20
89 29 137
89 52 13
89 57 10
89 97 23
89 1 37
89 1 12
89 1 3
52 1 11
52 1 31
52 1 16
52 1 6
52 1 10
52 1 13
52 1 10
52 1 25
52 1 2
52 59 38
52 97 75
57 1 14
57 1 13
57 1 14
57 114 12
57 1 23
57 06 26
I need create a
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
2006 Dec 03
1
passing an argument to a function which is also to be a dataframe column name
any suggestions on the following gratefully welcome,
I have a dataframe, which I am subsetting via labels
atpi[, creativity]
where (for example)
atpi = as.data.frame(matrix(1:50, ncol = 5, nrow = 10))
names(atpi) = c("Q1", "Q2", "Q3", "Q4", "Q5")
and
creativity = c("Q1", "Q3", "Q4")
I want to add an extra column
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
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',