Moving Averange

Short examples for moving average and cumulative average usig R. Moving average Some alternatives to do moving average, sometimes called running mean or rolling mean. You can use base R, data.table or zoo package. Use function frollmean from data.table package or rollmean from zoo package.

Read More

Error handling

Handling error in R can easily be done with debugger or by activating error options with recover. options(error = recover) Or to activate warning as error with: options(warn = 2) Nevertheless this blog post explain nicely other alternative including the code below that you can put in your .

Read More

Subset DT

Subsetting data.table can be done using base R subset with S3 Class for data.table object. Alternatively is to use the recode approach as mentioned in StackOverflow. lookup <- list(v1 = 1:3, v2 = letters[5:7]) DT[lookup, on = names(lookup), nomatch = NULL] This will return all columns in DT that match lookup list.

Read More

Good to know

Updated: 2023-06-09 Things that I find it useful during my work: Debuging warnings Sometimes it’s nice to know where in the code that generate warnings especially when it’s related to NA introduced by coercion. To do this we can change the options to make warning as error.

Read More