Re: [R] define variables from rows of a matrix

2011-08-10 Thread Eik Vettorazzi
Hi, I was irritated about your printed last row of A, which apart from definition contains a 20. Anyway, how about this: y<-x<-rep(NA,nrow(A)) #its not clear, whether multiple values of 100 can occur in a single #row, and what to do, when 100 is found before and after 20, so you may #alter the in

[R] define variables from rows of a matrix

2011-08-09 Thread gallon li
I have a following matrix and wish to define a variable based the variable A=matrix(0,5,5) A[1,]=c(30,20,100,120,90) A[2,]=c(40,30,20,50,100) A[3,]=c(50,50,40,30,30) A[4,]=c(30,20,40,50,50) A[5,]=c(30,50,NA,NA,100) > A [,1] [,2] [,3] [,4] [,5] [1,] 30 20 100 120 90 [2,] 40 30 2