Alice Lin <alice.ly <at> gmail.com> writes: > > > I have a vector of binary data – a string of 0’s and 1’s. > I want to weight these inputs with a normal kernel centered around entry x > so it is transformed into a new vector of data that takes into account the > values of the entries around it (weighting them more heavily if they are > near). > > Example: > - > - - > - - > 0 1 0 0 1 0 0 1 1 1 1 > If x = 3, it’s current value is 0 but it’s new value with the Gaussian > weighting around would be something like .1*0+.5*1+1*0+0.5*0+.1*1= 0.6 > > I want to be able to play with adjusting the variance to different values as > well. > I’ve found wkde in the mixtools library and think it may be useful but I > have not figured out how to use it yet. > > Any tips would be appreciated. > > Thanks! >
I don't know anything about wkde. But the filter function in stats package should do what you want. > x <- c(0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) > filter(x, c(.1, .5, 1, .5, .1)) Time Series: Start = 1 End = 11 Frequency = 1 [1] NA NA 0.6 0.6 1.0 0.6 0.7 1.6 2.1 NA NA In the signal package, there is also a variety of windows, including the gausswin function. However, the filter function in the signal package masks the filter function from the stats package > stats::filter(x, gausswin(5, 2.68)) Mark Lyman Statistician, ATK Launch Systems ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.