From MSchwartz at MedAnalytics.com  Tue Mar 15 19:53:38 2005
From: MSchwartz at MedAnalytics.com (Marc Schwartz)
Date: Tue Mar 15 19:53:53 2005
Subject: [Rd] Lemon drops
In-Reply-To: <x2mzt4om5l.fsf@biostat.ku.dk>
References: <x2r7igon5j.fsf@biostat.ku.dk>
	<1110907737.8170.17.camel@horizons.localdomain>
	<x2mzt4om5l.fsf@biostat.ku.dk>
Message-ID: <1110912819.8170.36.camel@horizons.localdomain>

On Tue, 2005-03-15 at 18:26 +0100, Peter Dalgaard wrote:
> Marc Schwartz <MSchwartz@MedAnalytics.com> writes:
> 
> > On Tue, 2005-03-15 at 18:05 +0100, Peter Dalgaard wrote:
> > > I bumped into the following situation:
> > > 
> > > Browse[1]> coef
> > >             deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP
> > > (Intercept)    462    510    528    492    660    762
> > > Browse[1]> coef[,1]
> > > [1] 462
> > > Browse[1]> coef[,1,drop=F]
> > >             deg0NA
> > > (Intercept)    462
> > > 
> > > where I really wanted neither, but
> > > 
> > > (Intercept)
> > >         462
> > > 
> > > Anyone happen to know a neat way out of the conundrum?
> > > 
> > > I can think of
> > > 
> > > rowSums(coef[,1,drop=F])
> > > 
> > > or of course
> > > 
> > > val <- coef[,1]
> > > names(val) <- rownames(x))
> > > 
> > > but the first one is sneaky and the second gets a bit tedious...
> > 
> > Peter,
> > 
> > How about something like this:
> > 
> > > x
> >             deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP
> > (Intercept)    462    510    528    492    660    762
> > IV1              1      2      3      4      5      6
> > 
> > 
> > > x[1]
> > (Intercept)
> >         462
> > 
> > > str(x[1])
> >  Named num 462
> >  - attr(*, "names")= chr "(Intercept)"
> > 
> > 
> > Does that work or am I missing something?
> 
> You're missing the context. What I really need is something that will
> extract a column of a matrix as a vector in the usual way, but will
> not get confused if there is only one row.


OK.  <scratching head.....>

Well, thinking that there was an approach using t(), it works, but
retains a 2 dim structure which is not what you want. It also retains
the colname from the original structure as the rowname for the new
construct.

I don't have another idea at this point for you, but I'll keep
thinking... :-)

Marc


[Rd] Lemon drops
Marc Schwartz