Re: [R] creating matrices from vectors

From: Patrick Burns <pburns_at_pburns.seanet.com>
Date: Sat, 15 Nov 2008 17:52:59 +0000

I think this approximates what you want:

a1 <- 1:10
a2 <- a1 + 100
a3 <- a1 + 200
a4 <- a1 + 300

arr <- rbind(a1, a2, a3, a4)
dim(arr) <- c(2, 2, 10)
apply(arr, 3, function(x) eigen(x)$values[2])

Patrick Burns
patrick_at_burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

James Rudge wrote:
> If I have 4 vectors (a, b, c, and d) each of length 1000, how do I then create 1000 two by two matrices from these vectors, such that:
>
> myMatrix[i] = matrix(c(a[i],b[i],c[i],d[i]),2)
>
> Then I'd like to create a single vector containing the largest eigenvalues of each matrix?
>
> (Sorry I am quite new to R)
> Many thanks,
> James
>
> _________________________________________________________________
> [[elided Hotmail spam]]
>
> ______________________________________________
> 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.
>
>
>



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 Sat 15 Nov 2008 - 17:55:48 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 Sat 15 Nov 2008 - 18:30:26 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