Input:
df = data.frame(col1 = 1:5, col2 = 5:9)
rownames(df) <- letters[1:5]
#add jitter
jitter(df) #Error in jitter(df) : 'x' must be numeric
Expected output: jitter will be added to the columns of df
. Thanks!
The jitter() function is used to add noise to the numeric vector. The jitter() function takes a numeric vector and amount of noise to be added and returns a numeric vector of the same length but with an amount of noise added in order to break ties.
jitter
is a function that takes numeric
as input. You cannot simply run jitter
on the whole data.frame
. You need to loop through the columns. You can do:
data.frame(lapply(df, jitter))
Jitter
is to be applied to a numerical vector, not a dataframe.
If you want to apply Jitter to all your columns, this should do:
apply(df, 2, jitter)
Just adding random numbers?
df_jit <- df + matrix(rnorm(nrow(df) * ncol(df), sd = 0.1), ncol = ncol(df))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With