Run R script from command line

If you want the output to print to the terminal it is best to use Rscript Note that when using R CMD BATCH a.R that instead of redirecting output to standard out and displaying on the terminal a new file called a.Rout will be created. One other thing to note about using Rscript is that it doesn’t … Read more

How to get summary statistics by group

1. tapply I’ll put in my two cents for tapply(). You could write a custom function with the specific statistics you want or format the results: 2. data.table The data.table package offers a lot of helpful and fast tools for these types of operation:

Categories R

Error: Invalid input: date_trans works with objects of class Date only

The problem seems to be in your geom_rect area (it plots without this). Other “date_trans” errors on this site point to needed to set dates with as.Date. So yes, you were in the right debug area. This works: Wrap your minimum and maximum in xmin and xmax call in geom_rect section: CODE BELOW FOR OTHERS TO USE I created three data lines … Read more

Categories R

How to update a package in R?

You can’t do this I’m afraid, well, not with update.packages(). You need to call install.packages(“R2jags”) instead. You can’t install R2jags in the current session because you have already loaded the current version into the session. If you need to, save any objects you can’t easily recreate, and quit out of R. Then start a new R session, immediately run install.packages(“R2jags”), then … Read more

Categories R

remove all variables except functions

Here’s a one-liner that removes all objects except for functions: It uses setdiff to find the subset of objects in the global environment (as returned by ls()) that don’t have mode function (as returned by lsf.str())

Categories R

dcast warning: ‘Aggregation function missing: defaulting to length’

The reason why you are getting this warning is in the description of fun.aggregate (see ?dcast): aggregation function needed if variables do not identify a single observation for each output cell. Defaults to length (with a message) if needed but not specified So, an aggregation function is needed when there is more than one value for one spot … Read more

Categories R