I was doing some drawing in R and I needed to trim some values to keep the data (x axis) in reasonable limits, but I did not want to loose that info. Therefore, I summed the values that would be trimmed. Since I was repeating this, I wrote a function and commited it to the

gdata SVN package repository. It will probably take some time before new version of gdata hits the

CRAN, so there is

package for MS Windows and a

source package. Here it goes in action:

> x <- 1:10

> trimSum(x, n=5)

[1] 1 2 3 4 45

> trimSum(x, n=5, right=FALSE)

[1] 21 7 8 9 10

> x[9] <- NA

> trimSum(x, n=5)

[1] 1 2 3 4 NA

> trimSum(x, n=5, na.rm=TRUE)

[1] 1 2 3 4 36

*Related*

To

**leave a comment** for the author, please follow the link and comment on their blog:

** Gregor Gorjanc**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** R