Displaying 20 results from an estimated 9000 matches similar to: "conditional rowsums in sapply"
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
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 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
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',
2006 Nov 21
2
using nested ifelse and rowSums to create new variable?
Dear R-help community,
If I have a data.frame df as follows:
> df
x1 x2 x3 x4 x5 x6
1 5 5 1 1 2 1
2 5 5 5 5 1 5
3 1 5 5 5 5 5
4 5 5 1 4 5 5
5 5 1 5 2 4 1
6 5 1 5 4 5 1
7 5 1 5 4 4 5
8 5 1 1 1 1 5
9 1 5 1 1 2 5
10 5 1 5 4 5 5
11 1 5 5 2 1 1
12 5 5 5 4 4 1
13 1 5 1 4 4 1
14 1 1 5 4 5 5
15 1 5 5 4
2023 Oct 13
1
Create new data frame with conditional sums
This seems like it should be simple but I can't get it to work properly. I'm starting with a data frame like this:
Tract Pct Totpop
1 0.05 4000
2 0.03 3500
3 0.01 4500
4 0.12 4100
5 0.21 3900
6 0.04 4250
7 0.07 5100
8 0.09
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,
2023 Oct 14
2
Create new data frame with conditional sums
Well, here's one way to do it:
(dat is your example data frame)
Cutoff <- seq(0, .15, .01)
Pop <- with(dat, sapply(Cutoff, \(p)sum(Totpop[Pct >= p])))
I think there must be a more efficient way to do it with cumsum(), though.
Cheers,
Bert
On Sat, Oct 14, 2023 at 12:53?AM Jason Stout, M.D. <jason.stout at duke.edu> wrote:
>
> This seems like it should be simple but I
2010 Aug 12
3
Error in rowSums
Hi
I am trying to calculate the row sums of a matrix i have created
The matrix ( FeaturePresenceMatrix) has been created by
1) Read csv
2) Removing unnecesarry data using [-1:4,] command
3) replacing all the NA values with as.numeric(0) and all others with as.numeric
(1)
When I carry out the command
TotalFeature <- rowrowSums(FeaturePresenceMatrix, na.rm = TRUE)
I get the following
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
2011 Nov 21
4
Discarding a matrix based on the rowSums value
Hello
I would appreciate your help on the followig. I want to generate random
binary matrices but I need to discard those with all-1 rows. That is, for a
10x10 matrix with five 1's
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 0 0 0 0 0 0 0 0 0 1
[2,] 0 0 0 0 0 0 1 0 0 0
[3,] 0 0 0 0 0 0 1
2003 May 09
1
windows data editor changes dimensions displayed data frames
dear R-tists,
i am experiencing a problem with the data editor in the windows version of
R 1.6.1 envoked with the command 'fix'.
the data editor changes the size of large data frames.
a simple example illustrates this:
-------------------------------------------------------
> dfrm <- data.frame(no=c(1:100000))
> length(dfrm[,1])
[1] 100000
> fix(dfrm)
>
2010 Aug 13
2
Fw: Error in rowSums REPOST
For the query below I have also included the follwing information. Thanks for
your replies
> str(FeaturePresenceMatrix)
chr [1:65530, 1:40] "0" "0" "0" "0" "1" "0" "0" "0" "0" ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:65530] "4" "5" "6" "7" ...
2005 Nov 10
2
error in rowSums:'x' must be numeric
Dear All,
It's Eszter again from Hungary. I could not solve my problem form
yesterday, so I still have to ask your help.
I have a binary dataset of vegetation samples and species as a comma
separated file. I would like to calculate the Jaccard distance of the
dataset. I have the following error message:
Error in rowSums(x, prod(dn), p, na.rm) : 'x' must be numeric
In addition:
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.
2003 May 09
2
Re: [R] windows data editor changes dimensions displayed data frames (PR#2962)
On Fri, 09 May 2003 11:34:08 +0300, Bernd Ebersberger
<bernd.ebersberger@vtt.fi> wrote:
>dear R-tists,
>
>i am experiencing a problem with the data editor in the windows version of
>R 1.6.1 envoked with the command 'fix'.
>
>the data editor changes the size of large data frames.
I can confirm this in the current R-patched. I'll take a look. It
might be that
2005 Dec 01
1
Kalman Smoothing - time-variant parameters (sspir)
Dear R-brains,
I'm rather new to state-space models and would benefit from the extra
confidence in using the excellent package sspir.
In a one-factor model, If I am trying to do a simple regression where
I assume the intercept is constant and the 'Beta' is changing, how do
I do that? How do i Initialize the filter (i.e. what is appropriate to
set m0, and C0 for the example below)?
2023 Oct 14
1
Create new data frame with conditional sums
That's very helpful and instructive, thank you!
Jason Stout, MD, MHS
Box 102359-DUMC
Durham, NC 27710
FAX 919-681-7494
________________________________
From: John Fox <jfox at mcmaster.ca>
Sent: Saturday, October 14, 2023 10:13 AM
To: Jason Stout, M.D. <jason.stout at duke.edu>
Cc: r-help at r-project.org <r-help at r-project.org>
Subject: Re: [R] Create new data frame with