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.
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Example2
x2<-sample(1:100,200,replace=TRUE)
x2
Output-