A) A=rand(200,1) % 200 random numbers use rand or randn
b=randi(200,100,1) % randomly choose 100
A(b)=NaN % replace those 100 chosen above with NaN's
We may use the sample function to generate a random vector for a set of values. The sample function just requires that we pass the range and sample size. For instance, the command sample(1:100,20) can be used to generate a random sample of size 20 for a range of values between 1 and 100. If the sample size is greater than 100, replace=TRUE can be used as seen in the example below.
Example1 -
x1<-sample(1:100,20)
x1
x1
Output-
[1] 39 64 73 80 78 38 57 16 5 40 3 45 96 20 51 13 42 35 63 25
Example2
x2<-sample(1:100,200,replace=TRUE)
x2
Output-