# Matrix in R

6 messages
Open this post in threaded view
|

## Matrix in R

 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
Open this post in threaded view
|

## Re: Matrix in R

 danielepippo wrote    I'm building a matrix in R with a cycle for like this: pp_ris2=matrix(NA,6,6) for(i in 0:6){ ..... R is not like c, indexing starts with 1. Dieter
Open this post in threaded view
|

## Re: Matrix in R

 but if in my function pp_ris2[i,j]=myfunction}must be the indexes 0-0,0-1,0-2,0-3, ....?
Open this post in threaded view
|

## Re: Matrix in R

 On Feb 18, 2011, at 9:32 AM, danielepippo wrote: > > but if in my function > pp_ris2[i,j]=myfunction} > must be the indexes 0-0,0-1,0-2,0-3, ....? >  From a search of RSiteSearch() that started with with terms:  zero   matrix indexing http://finzi.psych.upenn.edu/R/Rhelp02/archive/39031.htmlhttp://finzi.psych.upenn.edu/R/Rhelp02/archive/26476.htmlhttp://finzi.psych.upenn.edu/R/Rhelp02/archive/32960.html> -- > View this message in context: http://r.789695.n4.nabble.com/Matrix-in-R-tp3312748p3312780.html> Sent from the R help mailing list archive at Nabble.com. -- David Winsemius, MD West Hartford, CT ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.