[R] Matrix in R

danielepippo danzur at hotmail.it
Fri Feb 18 15:17:27 CET 2011


Hi everyone,
   I'm building a matrix in R with a cycle for like this:
pp_ris2=matrix(NA,6,6)
for(i in 0:6){
	for(j in 0:6){
		if(i>j){
		pp_ris2[i,j]=myfunction}
	else if(i==j){
		print(c(i,j))
		pp_ris2[i,j]=myfunction}
	
}}

but the result is:
      [,1]     [,2]     [,3]    [,4]   [,5]    [,6]
[1,] 0.062   NaN    NaN    NaN   NaN   NaN
[2,] 0.083  0.022   NaN    NaN   NaN   NaN
[3,] 0.072  0.022  0.004   NaN   NaN   NaN
[4,] 0.046  0.016  0.003  0.001  NaN   NaN
[5,] 0.023  0.009  0.002  0.000   0      NaN
[6,] 0.010  0.004  0.001  0.000   0        0

my problem is in the first column and row because in this matrix there are
not the column and the row with i=0 and j=0. Can anyone help me please?

thanks a lot


-- 
View this message in context: http://r.789695.n4.nabble.com/Matrix-in-R-tp3312748p3312748.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list