Displaying 11 results from an estimated 11 matches for "totpop".
Did you mean:
hotpop
2023 Oct 15
2
Create new data frame with conditional sums
...ith using a loop to solve
> this problem, but it's generally a good idea to pre-allocate space for
> the result rather than build it up one value at a time, which may cause
> unnecessary copying of the object.
>
> Here are three solutions:
>
> f1 <- function(Cutoff, Pct, Totpop){
> Pop <- numeric(0)
> for (i in seq_along(Cutoff))
> Pop[i] <- sum(Totpop[Pct >= Cutoff[i]])
> cbind(Cutoff, Pop)
> }
>
> f2 <- function(Cutoff, Pct, Totpop){
> Pop <- numeric(length(Cutoff))
> for (i in seq_along(Cutoff))
> Po...
2023 Oct 14
1
Create new data frame with conditional sums
...that there's anything wrong with using a loop to solve
this problem, but it's generally a good idea to pre-allocate space for
the result rather than build it up one value at a time, which may cause
unnecessary copying of the object.
Here are three solutions:
f1 <- function(Cutoff, Pct, Totpop){
Pop <- numeric(0)
for (i in seq_along(Cutoff))
Pop[i] <- sum(Totpop[Pct >= Cutoff[i]])
cbind(Cutoff, Pop)
}
f2 <- function(Cutoff, Pct, Totpop){
Pop <- numeric(length(Cutoff))
for (i in seq_along(Cutoff))
Pop[i] <- sum(Totpop[Pct >= Cutoff[i]])
cb...
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 can't get it to work properly. I'm starti...
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 4700
9 0.06 4950
10...
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 new column with cutoffs
dummyData$Cutoff <- cut(dummyData$Pct, breaks = cutoffs,
?? ?labels = cutoffs[-1], order...
2019 Feb 19
2
Cambiar el formato de datos
...ear60 13411
> 5 Angola year60 5643182
> 6 Afghanistan year61 9166764
> 7 Albania year61 1659800
>
> On Tue, 19 Feb 2019 at 13:31, Antonio Rodriguez Andres <
> antoniorodriguezandres70 en gmail.com> wrote:
>
>> > gather(pobla, key = year, value = totpop, year60:year63)
>>
>> Country year totpop
>> 1 Afghanistan year60 8996351
>> 2 Albania year60 1608800
>> 3 Algeria year60 11124888
>> 4 Andorra year60 13411
>>
>> Gracias Carlos
>>
>> Antonio
>>
>>...
2023 Oct 16
1
Create new data frame with conditional sums
...r.
-- 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 <- seq(0, 0.20, by = by)
>
> # Create a new column with cutoffs
> dummyData$Cutoff <- cut(dummyData$Pct, breaks = cut...
2012 Sep 24
1
Adding textbox to multiple panels in lattice
...iSex <- with(iFrame,unique(sex))
if (iSex=="Female"){
panel.pyramid(x,y,...)
iCc <- with(iFrame,unique(cc))
iYr <- with(iFrame,unique(yr))
totpop <- round(sum(abs(subset(iEduDat,cc==iCc
& yr==iYr,select=value)))/1000,2)
LAB <- paste("Pop = ",totpop," Mio",sep="")
xr <-
max(abs(subset(iEduDat,cc==iCc,select=value)))
x...
2019 Feb 19
2
Cambiar el formato de datos
> gather(pobla, key = year, value = totpop, year60:year63)
Country year totpop
1 Afghanistan year60 8996351
2 Albania year60 1608800
3 Algeria year60 11124888
4 Andorra year60 13411
Gracias Carlos
Antonio
On Tue, 19 Feb 2019 at 12:54, Carlos Ortega <cof en qualityexcellence.es>
wrote:
> Sí, tienes...
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
2019 Feb 19
2
Cambiar el formato de datos
Estimados miembros de la comunidad de R
Tengo el siguiente formato en un fichero csv que corresponde a datos de la
población para un conjunto de países y para un rango amplio de años.
Pais 1960 1961 1962 1963
Albania vvvvv vvvv
Algeria vvvvv vvvv
Me gustaría pasarlo a la siguiente forma
Pais Año Poblacion
Albania 1960 vvv
Albania 1961 vvvv
Albania