# gdata gains trimSum function

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Gregor Gorjanc**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 trimSum(x, n=5) [1] 1 2 3 4 45 > trimSum(x, n=5, right=FALSE) [1] 21 7 8 9 10 > x[9] trimSum(x, n=5) [1] 1 2 3 4 NA > trimSum(x, n=5, na.rm=TRUE) [1] 1 2 3 4 36

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 about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.