[R] Creat a new list with names of other list
Petr Savicky
savicky at cs.cas.cz
Thu Mar 15 10:37:29 CET 2012
On Thu, Mar 15, 2012 at 01:44:10AM -0700, ali_protocol wrote:
> Hi all,
>
> I want to create a new list with names of another list. Eeach sublist from
> both lists is a matrix, but the matrices with the same name (eg. list.1
> [[1]] and list.2 [[1]]) have different dimensions. How can I create the 2nd
> list?
>
> tSE = list ()
> Norm <- names(Normal)
> names(tSE) <- Norm
>
>
> does not do it.
Hi.
The example is not reproducible, so the source of error
is unclear. Try this.
lst1 <- list(a=diag(2), b=diag(5), c=diag(3))
lst2 <- vector("list", length=length(lst1))
names(lst2) <- names(lst1)
lst2$a <- diag(4)
lst2
$a
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 1 0 0
[3,] 0 0 1 0
[4,] 0 0 0 1
$b
NULL
$c
NULL
Hope this helps.
Petr Savicky.
More information about the R-help
mailing list