How do I stop set.seed() after a specific line of code?
问题 I would like to end the scope of set.seed() after a specific line in order to have real randomization for the rest of the code. Here is an example in which I want set.seed() to work for "rnorm" (line 4), but not for "nrow" (line 9) set.seed(2014) f<-function(x){0.5*x+2} datax<-1:100 datay<-f(datax)+rnorm(100,0,5) daten<-data.frame(datax,datay) model<-lm(datay~datax) plot(datax,datay) abline(model) a<-daten[sample(nrow(daten),20),] points(a,col="red",pch=16) modela<-lm(a$datay~a$datax) abline