search for: dummydata

Displaying 7 results from an estimated 7 matches for "dummydata".

Did you mean: dummy_data
2023 Oct 16
1
Create new data frame with conditional sums
Dear Jason, The code could look something like: dummyData = data.frame(Tract=seq(1, 10, by=1), ?? ?Pct = c(0.05,0.03,0.01,0.12,0.21,0.04,0.07,0.09,0.06,0.03), ?? ?Totpop = c(4000,3500,4500,4100,3900,4250,5100,4700,4950,4800)) # Define the cutoffs # - allow for duplicate entries; by = 0.03; # by = 0.01; cutoffs <- seq(0, 0.20, by = by) # Create a ne...
2023 Oct 16
1
Create new data frame with conditional sums
...off). I believe looping is O(n^2). Jeff's approach using findInterval may be faster. Of course implementation details matter. -- Bert On Mon, Oct 16, 2023 at 4:41?AM Leonard Mada <leo.mada at syonic.eu> wrote: > > Dear Jason, > > The code could look something like: > > dummyData = data.frame(Tract=seq(1, 10, by=1), > Pct = c(0.05,0.03,0.01,0.12,0.21,0.04,0.07,0.09,0.06,0.03), > Totpop = c(4000,3500,4500,4100,3900,4250,5100,4700,4950,4800)) > > # Define the cutoffs > # - allow for duplicate entries; > by = 0.03; # by = 0.01; > cutoffs <- se...
2023 Oct 15
1
Create new data frame with conditional sums
Dear Jason, I do not think that the solution based on aggregate offered by GPT was correct. That quasi-solution only aggregates for every individual level. As I understand, you want the cumulative sum. The idea was proposed by Bert; you need only to sort first based on the cutoff (e.g. using an ordered factor). And then only extract the last value for each level. If Pct is unique, than you
2023 Oct 15
2
Create new data frame with conditional sums
...apply(Cutoff, function(c) sum(Totpop[Pct >= c])) > cbind(Cutoff, Pop) > } > > The first is similar to yours; the second pre-allocates space for the > result but still uses a loop; and the third avoids the loop. All produce > the same result, for example, > > > with(dummydata, f3(seq(0, 0.15, by=0.01), Pct, Totpop)) > Cutoff Pop > [1,] 0.00 43800 > [2,] 0.01 43800 > [3,] 0.02 39300 > [4,] 0.03 39300 > [5,] 0.04 31000 > [6,] 0.05 26750 > [7,] 0.06 22750 > [8,] 0.07 17800 > [9,] 0.08 12700 > [10...
2023 Oct 14
1
Create new data frame with conditional sums
...n(Cutoff, Pct, Totpop){ Pop <- sapply(Cutoff, function(c) sum(Totpop[Pct >= c])) cbind(Cutoff, Pop) } The first is similar to yours; the second pre-allocates space for the result but still uses a loop; and the third avoids the loop. All produce the same result, for example, > with(dummydata, f3(seq(0, 0.15, by=0.01), Pct, Totpop)) Cutoff Pop [1,] 0.00 43800 [2,] 0.01 43800 [3,] 0.02 39300 [4,] 0.03 39300 [5,] 0.04 31000 [6,] 0.05 26750 [7,] 0.06 22750 [8,] 0.07 17800 [9,] 0.08 12700 [10,] 0.09 12700 [11,] 0.10 8000 [12,] 0.11 8000 [...
2023 Oct 14
2
Create new data frame with conditional sums
...12700 > 11 0.10 8000 > 12 0.11 8000 > 13 0.12 8000 > 14 0.13 3900 > 15 0.14 3900 > 16 0.15 3900 > > I can do this with a for loop but it seems there should be an easier, vectorized way that would be more efficient. Here is a reproducible example: > > dummydata<-data.frame(Tract=seq(1,10,by=1),Pct=c(0.05,0.03,0.01,0.12,0.21,0.04,0.07,0.09,0.06,0.03),Totpop=c(4000,3500,4500,4100, > 3900,4250,5100,4700, >...
2023 Oct 13
1
Create new data frame with conditional sums
...22750 8 0.07 17800 9 0.08 12700 10 0.09 12700 11 0.10 8000 12 0.11 8000 13 0.12 8000 14 0.13 3900 15 0.14 3900 16 0.15 3900 I can do this with a for loop but it seems there should be an easier, vectorized way that would be more efficient. Here is a reproducible example: dummydata<-data.frame(Tract=seq(1,10,by=1),Pct=c(0.05,0.03,0.01,0.12,0.21,0.04,0.07,0.09,0.06,0.03),Totpop=c(4000,3500,4500,4100, 3900,4250,5100,4700,...