[1] 26300.38
Loops size estimates with maximum (solution)
NoteExercise
Copy the vector below into R.
dinosaur_lengths <- c(17.8013631070471, 20.3764452071665, 14.0743486294308, 25.65782386974, 26.0952008049675, 20.3111541103134, 17.5663244372533, 11.2563431277577, 20.081903202614, 18.6071626441984, 18.0991894513166, 23.0659685685892, 20.5798853467837, 25.6179254233558, 24.3714331573996, 26.2847248252537, 25.4753783544473, 20.4642089867304, 16.0738256364701, 20.3494171706583, 19.854399305869, 17.7889814608919, 14.8016421998303, 19.6840911485379, 19.4685885050906, 24.4807784966691, 13.3359960054899, 21.5065994598917, 18.4640304608411, 19.5861532398676, 27.084751999756, 18.9609366301798, 22.4829168046521, 11.7325716149514, 18.3758846100456, 15.537504851634, 13.4848751773738, 7.68561192214935, 25.5963348603783, 16.588285389794)- Write a function named
mass_from_length_maxthat takesdino_lengthas an argument. Ifdino_lengthis less than 20 estimate the mass of the dinosaur using the equationmass <- 0.73 * dino_length ^ 3.63. Ifdino_lengthis greater than or equal to 20 returnNAinstead. Run this function with 18 as the input. - Use
map_dbl()and this function to estimate the mass for every length indinosaur_lengths. - Write a function named
mass_from_length_minthat takesdino_lengthas an argument. Ifdino_lengthis greater than 23 estimate the mass of the dinosaur using the equationmass <- 0.73 * dino_length ^ 3.63. Ifdino_lengthis less than or equal to 23 use the equationmass <- 1.2 * dino_length ^ 1.5instead. Run this function with 24 as the input. - Use
map_dbl()and this function to estimate the mass for every length indinosaur_lengths.
CautionOutput solution
Part 1
Part 2
[1] 25262.027 NA 10767.568 NA NA NA 24072.130
[8] 4785.145 NA 29666.193 26830.297 NA NA NA
[15] NA NA NA NA 17439.569 NA 37544.201
[22] 25198.303 12928.490 36388.290 34962.862 NA 8854.525 NA
[29] 28846.165 35735.369 NA 31765.368 NA 5561.862 28349.410
[36] 15418.314 9218.648 1197.666 NA 19552.500
Part 3
[1] 74729.09
Part 4
[1] 90.12829 110.37580 63.36125 95233.73231 101260.01671
[6] 109.84572 88.34919 45.31868 107.99125 96.31667
[11] 92.39957 64700.86937 112.03292 94697.26240 79013.47072
[16] 103955.22632 92798.46518 111.08967 77.33216 110.15627
[21] 106.16134 90.03427 68.33546 104.79831 103.08203
[26] 80307.92869 58.44124 119.68476 95.20747 104.01715
[31] 115908.18734 99.07656 127.92641 48.22487 94.52651
[36] 73.49422 59.42260 25.56813 94407.87295 81.07435