Adding noise to a column of data I am working with this optdigits data set from UCI machine learning repository and want to create a new training dataset with noise. How to randomly add noise to a vector in R? say corrupt 10% of the values of the vector. 
 A: It depends on the kind of noise you want to add.
Here's an example:
x <- runif(100,100,150)  # this is our original vector, which I'm just making up

corrupt <- rbinom(length(x),1,0.1)    # choose an average of 10% to corrupt at random
corrupt <- as.logical(corrupt)
noise <- rnorm(sum(corrupt),1000,200) # generate the noise to add
x[corrupt] <- x[corrupt] + noise      # about 10% of x has been corrupted

Here's a plot of corrupted values against the original ones:

You should substitute your own vector and the kind of noise. 
Edit: I've just seen your response to my question. To get a random value from 0 to 9, you use sample like so:
noise <- sample(0:9,sum(corrupt),replace=TRUE)

and because you're replacing rather than adding, you then do:
x[corrupt] <- noise 

Giving this on the same data as before, and with the same values replaced:

If you wanted to replace a precise number of values (exactly 100 of 1000 values say, rather than an average of 100), you could sample to choose from a set of indices indicating which values to replace.
