Generate 5% of missing value in R

r

#1

Hi I am begginer in data science and i am beginning to use r.

I have a little knowledge about imputation of missing value, now my question is How can i make a data set has 5% of missing value in r?. My question is because i have one data set without missing value so i want to transformate it to 5% of missing value.

Thanks


#2

Just use the sample function. Here is an example for a single column:

df[sample(1:nrow(df), size=0.05*nrow(df), replace=FALSE), column] <- NA

#3

thanks for your prompt response.