[R-sig-Geo] Updating a column entry in a dataframe from another dataframe
Juliane Struve
juliane_struve at yahoo.co.uk
Fri Jun 27 01:00:31 CEST 2008
Dear list,
I am a new R user and wonder if somebody could help with this problem:
The entries in column "currentcentroid" in data frame "fish" change in relation to the entry in column "angles" (example is given below). "currentcentroid" is a gridpoint. After updating it according to "angles" I would like to also update the corresponding UTM coordinates "currentUTMX" and "currentUTMY" from data frame "WaterCentroids", which stores centroids and their corresponding UTM coordinates.
I would like to write an if statement that relates "currentcentroid" and "CurrentUTMX" and "CurrentUTMY" in dataframe "fish" to "centroid" and "UTMX" and "UTMY" in dataframe "WaterCentroids".But I am having a hrad time figuring it out. Is there anybody who could help or give me a hint ?
The purpose is to simulate the path of fish on a grid.
Many thanks..
Juliane
This is my dataframe so far:
nfish=10
startpoints=sample(282816,nfish)
anglesfromnorth=c(0,45,90,135,180,225,270,360)
anglenumber=sample(1:8,size=nfish,replace=TRUE)
angles=anglesfromnorth[anglenumber]
fish=data.frame(WaterCentroids[startpoints, 3:5],angles=angles,currentcentroid=0,currentUTMX=0, currentUTMY=0)
if (fish$angles==45){fish$currentcentroid=fish$centroid +1} else
{fish$currentcentroid=fish$centroid}
How do I update "currentUTMX" and "currentUTMY" from df[WaterCentroids] now ?
__________________________________________________________
Not happy with your email address?.
Get the one you really want - millions of new email addresses available now at Yahoo! http://uk.docs.yahoo.com/ymail/new.html
More information about the R-sig-Geo
mailing list