[R] keeping dim() for array

Leeds, Mark (IED) Mark.Leeds at morganstanley.com
Tue Nov 21 14:14:29 CET 2006


I think  pip[1,,drop = FALSE] should fix it, but check it to make sure.


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Roger Bivand
Sent: Tuesday, November 21, 2006 7:51 AM
To: Federico Calboli
Cc: r-help
Subject: Re: [R] keeping dim() for array

On Tue, 21 Nov 2006, Federico Calboli wrote:

> Hi All,
> 
> I noticed the following:
> 
> pip = array(1:6, dim = c(3,2))
> dim(pip)
> [1] 3 2
> 
> pup = pip[1,]
> dim(pup)
> NULL
> 
> I bet there is a *good* reason why one row of an array is 
> *dimensionless*, but it's highly inconvenient for my purpose, i.e. to 
> use apply() after an array goes through a number of logical steps and 
> is redimensioned, sometimes to one single row.
> 
> How do I keep dim(pup) to 1 2?

> pup = pip[1,,drop=FALSE]
> dim(pup)
[1] 1 2

R FAQ 7.5, by the way.

> 
> Since pup is at the end of a number of if(), it does not necessarily 
> end up as one row only, so t(as.matrix(pup)) is the *wrong* answer.
> 
> Best,
> 
> Federico
> 
> 

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

______________________________________________
R-help at stat.math.ethz.ch 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.
--------------------------------------------------------

This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}



More information about the R-help mailing list