hyongd的个人博客分享 http://blog.sciencenet.cn/u/hyongd

博文

working with data, exercise 1

已有 2494 次阅读 2013-9-10 01:42 |个人分类:生活点滴|系统分类:科研笔记

# 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.




https://blog.sciencenet.cn/blog-274809-723618.html

上一篇:Working with data
下一篇:重庆化粪池污水排入长江
收藏 IP: 131.118.230.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-27 04:09

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部