I all

I am trying to create a matrix for a network diagram: 
# 1. The following produces two dataframes. The table "place" is a
dataframe of all places made from "tra" a tracing table that has the
source place and destination place. The table "details" is a dataframe
of all source and destination properties.

src=rep(c(1:3),each=5)
des=c(16:30)
rsk=rep(3,5)
tra=data.frame(src,des,rsk)
ips=data.frame(c(1:40),c(41:80),c(81:120))
colnames(ips)=c("placeid","x","y")

place=c(tra$src,tra$des)
place=data.frame(unique(place))
colnames(place)="placeid"
place
details=merge(ips, place, by.x = "placeid", 
by.y = "placeid")[1:3]
details

# 2. The goal is to produce a matrix with source properties as rows and
destination properties as columns and a risk value (from the "details"
table) placed in the matrix where a trace has occurred. All other values
would be zero. 

trace.sna = matrix(rep(0, times = length(details[,1])^2), 
nrow =length(details[,1]))
trace.sna

for(i in 1:length(tra[,1])){
src = tra[i,1]
des = tra[i,2]
trace.sna[src, des]=tra[i,3]}

I get the error message:

Error in trace.sna[src, des] = tra[i, 3] : 
subscript out of bounds

There is something wrong with the highlighted code. I know that there
must be some descrepancy in the numbers of values I am using but don't
know why or how to fix it.

Thanks for your help in advance.


Kind regards

andy

Andrew McFadden MVS BVSc
Incursion Investigator
Investigation & Diagnostic Centres - Wallaceville Biosecurity New 
Zealand Ministry of Agriculture and Forestry




########################################################################
This email message and any attachment(s) is intended solely for the
addressee(s) named above. The information it contains is confidential
and may be legally privileged.  Unauthorised use of the message, or the
information it contains, may be unlawful. If you have received this
message by mistake please call the sender immediately on 64 4 8940100
or notify us by return email and erase the original message and
attachments. Thank you.

The Ministry of Agriculture and Forestry accepts no responsibility for
changes made to this email or to any attachments after transmission from
the office.
########################################################################

	[[alternative HTML version deleted]]

