R doesn't access arrays like C, use [i,j] to access a 2-d array, e.g.:
my_array <- array(0,dim=c(2,2))
for(i in seq(1,2,by=1)){
+ for(j in seq(1,2,by=1)){
+ my_array[i,j] = i+j
+ }
+ }
my_array
[,1] [,2]
[1,]23
[2,]34
tdm wrote:
Hi,
Can someone please give m
Could you possibly consider reading "An Introduction to R", especially the
first few pages of chapter 5, and also a bit about vectors from chapter 2,
and maybe eventually even some other parts...
You have x[i][j] where length(i)==1, so x[i] will be a single element.
Having [j] there makes no sense
On Wed, 14 Oct 2009, tdm wrote:
Hi,
Can someone please give me a pointer as to how I can set values of an array?
See
?Subscript
and study the examples.
What do you suppose
array( 1:4, dim=c(2, 2) )[1][2]
is? R is not C.
HTH,
Chuck
Why does the code below not work
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,]00
[2,]00
for(i in seq(1,2,by=1)){
for(j in seq(1,2,by=1)){
my_array[i][j] = 5
}
}
4 matches
Mail list logo