Displaying 4 results from an estimated 4 matches for "wsums".
Did you mean:
sums
2000 Sep 17
1
Weighted Histogram
...in a given interval.
Given equal-length vectors of data 'data' and weights 'w', and breaks
(intervals) for the histogram, I calculate a weighted histogram as
follows (see MASS's 'truehist' for an unweighted histogram):
bin <- cut(data, breaks, include.lowest = TRUE)
wsums <- sapply(split( w, f = bin), sum)
prob <- wsums/(diff(breaks) * sum(w))
where 'bin' is the recoded data vector, 'wsums' is the sum of weights
across each factor in 'bin', and 'prob' is the vector of probabilities
used to plot the true histogram.
But if...
2002 Feb 06
4
Weighted median
Is there a weighted median function out there similar to weighted.mean()
but for medians? If not, I'll try implement or port it myself.
The need for a weighted median came from the following optimization
problem:
x* = arg_x min (a|x| + sum_{k=1}^n |x - b_k|)
where
a : is a *positive* real scalar
x : is a real scalar
n : is an integer
b_k: are negative and positive scalars
2013 Feb 06
0
weighing proportion of rowSums in dataframe
...,
> here is a one-liner for a df without the rowSum column
>
> 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))
>
> (df$wSum<-apply(sweep(df[,-1],1,rowSums(df[,-1],na.rm=T),"/"),1,function(x)sum(x*w,na.rm=T)))
>
> hth.
>
> Am 06.02.2013 14:17, schrieb D. Alain:
> > 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...
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