Re: [R] Setting matrix dimnames in a list

From: jim holtman <jholtman_at_gmail.com>
Date: Thu, 08 May 2008 14:05:02 -0400

I think what you want is this -- you have to return 'x' from the lapply:

x <- matrix(1:4,2)
y <- matrix(5:8,2)

z <- list(x,y)
nm <- c("a","b")
nms <- list(nm,nm)

z <- lapply(z,function(x){

    dimnames(x)<-nms
    x
})

On Thu, May 8, 2008 at 1:33 PM, statmobile <statmobile_at_gmail.com> wrote:
> Hey All,
>
> I was wondering if I could solicit a little input on what I'm trying to do
> here. I have a list of matrices, and I want to set their dimnames, but all
> I can come up with is this:
>
> x <- matrix(1:4,2)
> y <- matrix(5:8,2)
>
> z <- list(x,y)
> nm <- c("a","b")
> nms <- list(nm,nm)
>
> z <- lapply(z,function(x)dimnames(x)<-nms)
>
> As you can see, this doesn't quite work. Could anybody help me, and bonus
> points if you can help me do this efficiently. Please cc my email address,
> because I only get summaries of the list.
>
> Thanks in advance!
>
> ______________________________________________
> R-help_at_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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_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.
Received on Thu 08 May 2008 - 18:07:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 08 May 2008 - 21:30:55 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive