[R] Generating these matrices going backwards

francogrex francogrex at mail.com
Thu Nov 15 08:37:46 CET 2007


Hi, thanks but the way you are doing it is to assign the values of N in the x
matrix, knowing from the example I have given where they are supposed to be.
While the assumption is, you ONLY have values of N and R and do NOT know
where they would be placed in the x and y matrix a-priori, but their
position has to be derived from only the (N and R) dataframe you have.


Chris Stubben wrote:
> 
> Maybe something like this?
> 
> N<-c(1,2,1,3)
> ## create empty matrix
> x<-diag(0,3)
> ## fill off diagonal
>  x[row(x)==col(x)+1]<-N[1:2]
> # fill 3rd column
>  x[1:2,3]<-N[3:4]
> 
> Or create a function and return both x and y
> 
> mat3<-function(N)
> {
>  x<-diag(0,3)
> # fill each element separately
> x[2,1]<-N[1]
> x[3,2]<-N[2]
> x[1,3]<-N[3]
> x[2,3]<-N[4]
> dimnames(x)<-list(c("D1", "D2", "D3"), c("E1", "E2", "E3"))
> y =sum(x) * x / (rowSums(x)%o%colSums(x)) 
> list(x=x,y=y)
> }
> mat3(N)
> 

-- 
View this message in context: http://www.nabble.com/Generating-these-matrices-going-backwards-tf4807447.html#a13763015
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list