||
# Begin Script 1 ----------------------------------------------------------------
# Write a script that creates 1000 random numbers by:
# (a) Making use of existing R functions for generating random numbers
# (b) Using a for-loop to dynamically add each newly-created random number to a
# vector
# (c) Same as (b), but using a while-loop
# (d) Same as (b), but using a nested for-loop to allocate 1000 random numbers
# to a symmetrical matrix
# (e) Use the system.time() function to determine the time R needs for (a)-(d)
# (f) Using the raster package, create a raster using your result from (d)
# (g) Using the raster package, write your result from (f) to a GeoTIFF
# Begin Script 2 ----------------------------------------------------------------
# Pick a random location from your raster map from Script_1(f) above & assume that
# that cell contains a population of invasive plants. Your task is to simulate
# and plot the dispersal of 100 seeds across the map that travel random distances
# and directions from this parent population.
# Here are the steps, with some hints:
# (1) Select a cell at random from the raster & obtain its x-y coordinate. HINT
# see ?xyFromCell in the raster package.
# (2) Generate 100 random directions & distances. HINTS: Be sure your distances
# are generally short enough so that the seeds do not land off the map & try
# using the rexp function to cluster the seeds around the parent population.
# Directions must be in radians (i.e., between -pi, pi).
# (3) Calculate new coordinates of all 100 seeds. HINT: Here is the code:
# new.x <- cell.x + dispersal.dist * sin(direction)
# new.y <- cell.y + dispersal.dist * cos(direction)
# (4) Plot the raster map and add symbols for (i) the initial infested location
# and (ii) the 100 seed dispersal events. Be sure the symbols differ between the
# parent population and the seeds. See ?points for help.
# (5) Use the pdf function to write your map to disc.
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-4-27 04:09
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社