[R] Array Dimension Names
Benjamin.STABLER@odot.state.or.us
Benjamin.STABLER at odot.state.or.us
Fri Oct 31 22:33:35 CET 2003
Oh yeah, thanks. I thought I might write a function such as getNames() that
returns the dimension number of the names of the dimnames of an object.
That way I don't have to rewrite apply, sweep, and aperm. But even better
would be for R to allow character names in addition to index numbers for the
MARGIN argument to apply and sweep, and the perm argument to aperm.
Thanks again,
Ben Stabler
>-----Original Message-----
>From: Tony Plate [mailto:tplate at blackmesacapital.com]
>Sent: Friday, October 31, 2003 1:07 PM
>To: STABLER Benjamin; r-help at stat.math.ethz.ch
>Subject: Re: [R] Array Dimension Names
>
>
>You can already name dimensions using standard arrays (but you
>can't use
>these names for the MARGIN argument of apply) e.g.:
>
> > x <- array(1:6, 3:2,
>dimnames=list(rows=letters[1:3],cols=LETTERS[24:25]))
> > x
> cols
>rows X Y
> a 1 4
> b 2 5
> c 3 6
> > apply(x, 2, sum)
> X Y
> 6 15
> > apply(x, "cols", sum)
>Error in -MARGIN : Invalid argument to unary operator
> >
>
>You could pretty easily create your own version of apply()
>that checked if
>MARGIN was character, and if it were, matched it against
>names(dimnames(X))
>
>hope this helps,
>
>Tony Plate
>
>At Friday 12:50 PM 10/31/2003 -0800,
>Benjamin.STABLER at odot.state.or.us wrote:
>>I would like to reference array dimensions by name in an
>apply and a summary
>>function. For example:
>>
>>apply(x, "workers", sum)
>>
>>Is there a better way to do this than creating a new
>attribute for the array
>>and then creating new methods for apply and summary? I don't
>want to name
>>the individual elements of each dimension (such as with
>dimnames) but rather
>>name the dimensions. Thanks for your help.
>>
>>Benjamin Stabler
>>Transportation Planning Analysis Unit
>>Oregon Department of Transportation
>>555 13th Street NE, Suite 2
>>Salem, OR 97301 Ph: 503-986-4104
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
More information about the R-help
mailing list