R code snippets

R code snippets

Initialize an empty vector and add things to it

vec <- numeric(0)
vec <- c(vec, i)

Replace values of a vector following a condition with something else

vec[is.na(vec)] <- a

Disable scientific notation in R

options(scipen = 999)