s-news
[Top] [All Lists]

Re: how to extract the elements of a list of vectors in a fixed position

To: "'David L Lorenz'" <lorenz@usgs.gov>, "'carol white'" <wht_crl@yahoo.com>
Subject: Re: how to extract the elements of a list of vectors in a fixed position?
From: "Alan Hochberg" <alan.hochberg@prosanos.com>
Date: Thu, 15 Nov 2007 14:33:15 -0500
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <OF2C39F3B9.FFE070DD-ON86257394.006652B7-86257394.00674F43@usgs.gov>
References: <123091.91024.qm@web62001.mail.re1.yahoo.com> <OF2C39F3B9.FFE070DD-ON86257394.006652B7-86257394.00674F43@usgs.gov>
Thread-index: AcgnuC/UOOGD5gNJT9OvERXJWKrTMgABV9og

This should avoid the issues with varying vector lengths and/or deprecated functions:

 

> lst <- list(c(1,2), c(3,4), c(5), c(6,7,8))

> unlist(lapply(lst,function(x) {x[2]}))

[1]  2  4 NA  7

>  

 

Best,

 

Alan

 

Alan Hochberg

VP, Research

ProSanos Corporation

225 Market St. Ste. 502,

Harrisburg, PA 17101

Tel 717-635-2124 * Fax 717-635-2575

 

 

<Prev in Thread] Current Thread [Next in Thread>