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.
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 -- View this message in context: http://r.789695.n4.nabble.com/Matrix-in-R-tp3312748p3312764.html Sent from the R help mailing list archive at Nabble.com.
but if in my function pp_ris2[i,j]=myfunction} must be the indexes 0-0,0-1,0-2,0-3, ....? -- 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.
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.html http://finzi.psych.upenn.edu/R/Rhelp02/archive/26476.html http://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
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, ....?I came across a posting in r-help that called this package "blasphemy": http://cran.r-project.org/web/packages/Oarray/index.html>-- David Winsemius, MD West Hartford, CT