Skip to content
Prev 309572 / 398506 Next

convert list without same component length to matrix

Hi,
You can also use:
sapply(l,`[`,1:4)
#???? [,1] [,2] [,3] [,4] [,5]
#[1,]??? 1??? 3??? 4??? 2??? 3
#[2,]??? 2??? 4??? 2??? 4??? 5
#[3,]??? 3??? 5??? 5??? 6??? 7
#[4,]??? 7??? 6??? 7??? 3??? 2
A.K.



----- Original Message -----
From: D. Rizopoulos <d.rizopoulos at erasmusmc.nl>
To: Al Ehan <aehan3616 at gmail.com>
Cc: "r-help at r-project.org" <r-help at r-project.org>
Sent: Thursday, November 1, 2012 4:19 AM
Subject: Re: [R] convert list without same component length to matrix

try this:

l <- list(c(1,2,3,7), c(3,4,5,6,3), c(4,2,5,7), c(2,4,6,3,2), c(3,5,7,2))

sapply(l, head, 4)


I hope it helps.

Best,
Dimitris
On 11/1/2012 9:11 AM, Al Ehan wrote: