x = c( 4 , 4 , 0 ) y = c( 1 , 0 , 2 )
t = c( 1 , 2, 2 ) r <- as.vector(table(t)) Nx <- vector("list",length(unique(t))) Ny <- vector("list",length(unique(t))) n <- vector("list",length(unique(t))) for(i in 1:length(unique(t))){ Nx[[i]] <- array(0,dim=c(1,r[i],1))+x[t==i]+1 Ny[[i]] <- array(0,dim=c(1,r[i],1))+y[t==i]+1 n[[i]] <- (Nx[[i]])*(Ny[[i]]) } Nx;Ny;n mult <- vector("list",length(unique(t))) for(i in 1:length(unique(t))){ for(k in 1:r[i]){ mult[[i]] <- array(1,dim=c(2,2,n[[i]][k],k)) } } mult On Mon, Oct 29, 2012 at 2:11 AM, Richard M. Heiberger <r...@temple.edu>wrote: > This time the code works, except for the spurious "}" at the end. > > I still don't know what the goal is. > > Please help yourself and us by putting spaces around assignment arrows > a <- b > instead of the hard-to-read > a<-b > and putting spaces after "," > > ## Let > a <- 12 > ## Does > a<-3 > ## mean > a <- 3 > ## or > a< -3 > ## ? > > Rich > > > On Sun, Oct 28, 2012 at 7:51 PM, Loukia Spineli <spinelilouki...@gmail.com > > wrote: > >> I am "refreshing" the code for the problem >> x = c( 4 , 4 , 0 ) >> >> y = c( 1 , 0 , 2 ) >> >> t = c( 1 , 2, 2 ) >> >> r<-as.vector(table(t)) >> >> Nx<-vector("list",length(unique(t))) >> Ny<-vector("list",length(unique(t))) >> n<-vector("list",length(unique(t))) >> for(i in 1:length(unique(t))){ >> Nx[[i]]<-array(0,dim=c(1,r[i],1))+x[t==i]+1 >> Ny[[i]]<-array(0,dim=c(1,r[i],1))+y[t==i]+1 >> n[[i]]<-(Nx[[i]])*(Ny[[i]]) >> } >> Nx;Ny;n >> >> mult<-vector("list",length(unique(t))) >> for(i in 1:length(unique(t))){ >> for(k in 1:r[i]){ >> mult[[i]]<-array(1,dim=c(2,2,n[[i]][k],k)) >> } >> } >> mult >> } >> Nx;Ny;n >> >> mult<-vector("list",length(unique(t))) >> for(i in 1:length(unique(t))){ >> for(k in 1:r[i]){ >> mult[[i]]<-array(1,dim=c(2,2,n[[i]][k],k)) >> } >> } >> mult >> >> On Mon, Oct 29, 2012 at 1:47 AM, Richard M. Heiberger <r...@temple.edu >> >wrote: >> >> > It still can't work. you didn't define tn. >> > >> > Please pick up your sample code from the email before sending it and >> > run it in a fresh R session. >> > >> > Please stay on list. Your last reply was only to me. >> > >> > Rich >> > >> > >> > On Sun, Oct 28, 2012 at 7:41 PM, Loukia Spineli < >> spinelilouki...@gmail.com >> > > wrote: >> > >> >> Thank you very much Richard for your quick reply! This is the whole >> code! >> >> I am stuck in this problem since a week (and my project has been >> paused due >> >> to this problem). If only it can bi fixed! >> >> x = c( 4 , 4 , 0 ) >> >> >> >> y = c( 1 , 0 , 2 ) >> >> >> >> t = c( 1 , 2, 2 ) >> >> >> >> r<-as.vector(table(t)) >> >> >> >> Nx<-vector("list",length(unique(t))) >> >> Ny<-vector("list",length(unique(t))) >> >> n<-vector("list",length(unique(t))) >> >> for(i in 1:length(unique(t))){ >> >> Nx[[i]]<-array(0,dim=c(1,tn[i],1))+x[t==i]+1 >> >> Ny[[i]]<-array(0,dim=c(1,tn[i],1))+y[t==i]+1 >> >> n[[i]]<-(Nx[[i]])*(Ny[[i]]) >> >> } >> >> Nx;Ny;n >> >> >> >> mult<-vector("list",length(unique(t))) >> >> for(i in 1:length(unique(t))){ >> >> for(k in 1:r[i]){ >> >> mult[[i]]<-array(1,dim=c(2,2,n[[i]][k],k)) >> >> } >> >> } >> >> mult >> >> >> >> >> >> >> >> On Mon, Oct 29, 2012 at 1:36 AM, Richard M. Heiberger <r...@temple.edu >> >wrote: >> >> >> >>> Your example is hard to understand because it includes multiple copies >> >>> of the >> >>> number "1". Let me do something with different values and see if it >> >>> gets what >> >>> you are after. Your code as posted can't work because the variable n >> is >> >>> not >> >>> defined. >> >>> >> >>> >> >>> result <- list(a=array(1:48, dim=c(2,2,3,4)), >> >>> b=array(49:96, dim=c(2,2,4,3))) >> >>> result >> >>> >> >>> >> >>> On Sun, Oct 28, 2012 at 7:01 PM, Loukia Spineli < >> >>> spinelilouki...@gmail.com> wrote: >> >>> >> >>>> Dear all, >> >>>> >> >>>> I want to obtain the following result >> >>>> >> >>>> [[1]] >> >>>> , , 1, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 2, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> ................ >> >>>> >> >>>> , , 9, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 10, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> >> >>>> [[2]] >> >>>> , , 1, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 2, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 3, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 4, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 5, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 1, 2 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 2, 2 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 3, 2 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> This is the code I have written. >> >>>> t = c( 1 , 2, 2 ) >> >>>> r<-as.vector(table(t)) >> >>>> >> >>>> mult<-vector("list",length(unique(t))) >> >>>> for(i in 1:length(unique(t))){ >> >>>> for(k in 1:r[i]){ >> >>>> mult[[i]]<-array(1,dim=c(2,2,n[[i]][k],k)) >> >>>> } >> >>>> } >> >>>> mult >> >>>> >> >>>> The results are correct for the array [[1]]. However for the array >> >>>> [[2]] I >> >>>> get the following result: >> >>>> [[2]] >> >>>> , , 1, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 2, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 3, 1 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> , , 1, 2 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 2, 2 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> , , 3, 2 >> >>>> >> >>>> [,1] [,2] >> >>>> [1,] 1 1 >> >>>> [2,] 1 1 >> >>>> >> >>>> How could I correct the code? >> >>>> >> >>>> [[alternative HTML version deleted]] >> >>>> >> >>>> ______________________________________________ >> >>>> R-help@r-project.org mailing list >> >>>> https://stat.ethz.ch/mailman/listinfo/r-help >> >>>> PLEASE do read the posting guide >> >>>> http://www.R-project.org/posting-guide.html >> >>>> and provide commented, minimal, self-contained, reproducible code. >> >>>> >> >>> >> >>> >> >> >> > >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.