The following code chunk takes about 20-25 seconds to run: set.seed (1) dat


The following code chunk takes about 20-25 seconds to run:<br>set.seed (1)<br>dat <- rnorm(100000)<br>output <- NULL<br>for (i in 1:(length(dat)-1)){<br>if(dat[i] < ®){<br>dat[i] <- dat[i] * -1<br>}<br>if(dat[i+1] < 0){<br>dat[i+1] <- dat[i+1] * -1<br>}<br>output <- c(output, mean(dat[i:(i+1)]) - sqrt(pi^50/exp(50)))<br>}<br>Modify the code to yield the same output but to run faster. There are at<br>least three ways to increase the speed.<br>

Extracted text: The following code chunk takes about 20-25 seconds to run: set.seed (1) dat <- rnorm(100000)="" output=""><- null="" for="" (i="" in="" 1:(length(dat)-1)){="" if(dat[i]="">< ®){="" dat[i]=""><- dat[i]="" *="" -1="" }="" if(dat[i+1]="">< 0){="" dat[i+1]=""><- dat[i+1]="" *="" -1="" }="" output=""><- c(output,="" mean(dat[i:(i+1)])="" -="" sqrt(pi^50/exp(50)))="" }="" modify="" the="" code="" to="" yield="" the="" same="" output="" but="" to="" run="" faster.="" there="" are="" at="" least="" three="" ways="" to="" increase="" the="">

Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here