I have example data as follows:
library(data.table)
sample <- fread("
A,0,L,2,2
B,4,K,3,0
")
names(sample) <- c("type", "value1", "cat", "value2", "value3")
I would like to add a random value, to every numerical value in the dataset. I would like that random value to have a mean of 0, and a standard deviation of 0.1 * each column mean.
I made a start as follows, but I am getting a little bit confused as how to store the values and how to use the apply function correctly here.
fetch_cols <- which(sapply(dat, is.numeric))
lapply(sample[, fetch_cols], rnorm(1, 0, 0.1*mean(sample[, fetch_cols])))
Desired output would be something like:
library(data.table)
sample <- fread("
A,-0.2,L,1.9,2.15
B,4.2,K,3.1,-.05
")