[R] populating an array

tdm philb at philbrierley.com
Thu Oct 15 07:23:25 CEST 2009


Hi,

Can someone please give me a pointer as to how I can set values of an array?

Why does the code below not work?

my_array <- array(dim=c(2,2))
my_array[][] = 0
my_array
     [,1] [,2]
[1,]    0    0
[2,]    0    0
 
for(i in seq(1,2,by=1)){
 for(j in seq(1,2,by=1)){
 my_array[i][j] = 5
 }
 }

Warning messages:
1: In my_array[i][j] = 5 :
  number of items to replace is not a multiple of replacement length
2: In my_array[i][j] = 5 :
  number of items to replace is not a multiple of replacement length

 my_array
     [,1] [,2]
[1,]    5    0
[2,]    5    0
 
 

-- 
View this message in context: http://www.nabble.com/populating-an-array-tp25903190p25903190.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list