[R] dimnames in array

aleksandr russell sss736 at gmail.com
Wed Aug 8 12:19:38 CEST 2012


Hello,

I'm working with an array; I'm trying to make it so that an array of
dim(42,2,2) has names whose length corresponds to that of the array,
and am hoping someone with experience with this can see what I'm not
doing correctly:




data11 = array(0,c(41,2,2))

y = lsoda(x0,times,fhn$fn.ode,pars)#This is make.fhn() from colloc
infer package#
  y = y[,2:3]

data11<-array(0,c(41,2,2))


 m8<-cbind(.29,1:41)
    m9<-as.array(m8,dim=c(41,2))

  data11[,1,] = y+m9
   data11[,2,] = y+m9

rownames(data2, do.NULL = FALSE, prefix="row")
varnames=c("V","R")
colnames(data6)=c("one","two")
colnames(data10)=colnames(data6)
 dimnames(data11)=list(rownames(data2),varnames,colnames(data10))
 data11a<-as.array(data11,dimnames=dimnames(data11))
 attributes(data11a)

#so this seems to print out the array attributes as they
should be: two sets of two columns each, and the first column of
each set is called 'v' and the second 'r'- no problem#

now the analysis from colloc infer(I've put it in below*)
takes this array but will not complete the analysis, saying

	"Error in `colnames<-`(`*tmp*`, value = c("V", "R")) :
  length of 'dimnames' [2] not equal to array extent"

When I type in

	length(dimnames(data11a)[2])

I get the answer:

	[1] 1

which seems odd when

	dimnames(data11a)[2]

gives

	[[1]]
	[1] "V" "R"

I would like to ask "How can I get the names of the second dimension
of the array(data11a) to have length "2" ?

It seems to me that the analysis will run if I can make this array
have the correct length dimnames

I thank you for your help.

____________


*
  fd.data11a = data11a
  DEfd11a = Data2fd(fd.data11a, times, bbasis,
  fdnames=list(NULL,NULL,varnames))


 profile11a.obj=LS.setup(pars,DEfd11a$coefs,fhn,basisvals=bbasis,lambda,fd.obj=NULL,
  more=NULL,data=data11a,weights=NULL,times=times,quadrature=NULL,eps=1e-6,
  posproc=FALSE,poslik=FALSE,discrete=FALSE,names=NULL,sparse=FALSE)
 lik = profile11a.obj$lik
 proc = profile11a.obj$proc
 qwts = rep(1/length(knots),length(knots))
  qwts = qwts %*% t(lambda)
  weights = array(1,dim(data11a))
  likmore = make.id()
  likmore$weights = weights
  lik = make.SSElik()
  lik$more = likmore
  lik$bvals = eval.basis(times,bbasis)
  procmore = make.fhn()
  procmore$weights = qwts
  procmore$qpts = qpts
  procmore$names = varnames
  procmore$parnames = parnames
  proc = make.SSEproc()
  proc$more = procmore
  proc$bvals = list(bvals = eval.basis(procmore$qpts,bbasis,0),
  dbvals = eval.basis(procmore$qpts,bbasis,1))
 res11a = inneropt(coefs, times=times, data=data11a, lik=lik, proc=proc,
  pars=spars, in.meth='nlminb', control.in=control.out)



More information about the R-help mailing list