gdata gains trimSum function

December 20, 2008

(This article was first published on Gregor Gorjanc, and kindly contributed to R-bloggers)

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

To leave a comment for the author, please follow the link and comment on their blog: Gregor Gorjanc. 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...


Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)