I have a list of groups of xy positions I want to set to 0 in an  
array full of 1s. When the assignments are done directly from the  
list, they are incorrect, while if I use a temporary array derived  
from the list the assignments are correct. The following example will  
hopefully make my problem clearer.

The matrices z and zz are initialised with 1. The z and zz values at  
coordinates in list x are then set to 0 using two different methods.  
Although either method should lead to the same results, z and zz are  
different. z is incorrect, because some values in its first row have  
been incorrectly set to 0.

x  <- list( matrix( c( 9, 9, 74, 75 ), nrow=2 ),
             matrix( c( 11, 11, 34, 35 ), nrow=2 ),
             matrix( c( 14, 15, 58, 58 ), nrow=2 ),
             c( 16, 142 ),
             matrix( c( 19, 19, 94, 95 ), nrow=2 ),
             matrix( c( 19, 20, 127, 127 ), nrow=2 ),
             matrix( c( 22, 22, 112, 113 ), nrow=2 ),
             c( 23, 13 ),
             matrix( c( 26, 27, 81, 81 ), nrow=2 ),
             matrix( c( 31, 32, 153, 153 ), nrow=2 ) )
xx <- do.call( "rbind", x )

z <- matrix( 1, ncol=249, nrow=240 )
zz <- matrix( 1, ncol=249, nrow=240 )

for( k in x ) z[k] <- 0
zz[xx] <- 0

sum( z != zz )
c( sum( z[,1] != 1 ), sum( zz[,1] != 1 ) )

Somewhere, I must be doing something wrong, or assuming something  
incorrect. I would be very grateful if anybody could point me in the  
right direction.

platform       i386-apple-darwin8.8.1
arch           i386
os             darwin8.8.1
system         i386, darwin8.8.1
status
major          2
minor          4.1
year           2006
month          12
day            18
svn rev        40228
language       R
version.string R version 2.4.1 (2006-12-18)

(same results with platform i386-pc-mingw32, R version 2.4.1 and  
platform x86_64-unknown-linux-gnu, R version 2.3.1)

--
Dr Eric Blanc
Lecturer in Bioinformatics
MRC Centre for Developmental Neurobiology
King's College London
New Hunt's House Room 4.10B
Guy's Hospital Campus
London SE1 1UL

E-mail: eric.blanc@kcl.ac.uk
Tel: +44 (0)20 7848 6532
Fax: +44 (0)20 7848 6550




	[[alternative HTML version deleted]]

