| To: | carol white <wht_crl@yahoo.com> |
|---|---|
| Subject: | Re: how to extract the elements of a list of vectors in a fixed position? |
| From: | David L Lorenz <lorenz@usgs.gov> |
| Date: | Thu, 15 Nov 2007 12:48:28 -0600 |
| Cc: | s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu |
| In-reply-to: | <123091.91024.qm@web62001.mail.re1.yahoo.com> |
|
Carol, If you know in advance that all vectors have the same length, then you can convert the list to a data.frame and extract the data in the row that you want. Try as.data.frame(list (c(1,2), c(3, 4)))[2,] returns X.1 X.2 2 2 4 Note that if the length of the vectors are not all the same, as.data.frame will fail unless the length of all of the shorter vectors are numeric factors of the length of the longest vector so that the values are replicated correctly. Note that it also names the components There is also a deprecated function as.data.sheet(), which is in S-PLUS 7.0, that will allow you to convert the list to a rectangular object so that you can extract any row you want. It will return a value of NA for any vector shorter than the requested element. There are good reasons for deprecating the function, but there are times when it comes in handy like this. Dave
Hi, How is it possible to extract the elements of a list of vectors in a fixed position? suppose that I have a list of 2-element vectors, how can I extract the 2nd element of all vectors in the list? Can it be done with indexing and not by element name because my elements don't have name? Thanks carol So in this example, I want to extract 2 and 4 v = list (c(1,2), c(3, 4)) > v [[1]] [1] 1 2 [[2]] [1] 3 4
Be a better pen pal. Text or chat with friends inside Yahoo! Mail. See how.
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | how to extract the elements of a list of vectors in a fixed position?, carol white |
|---|---|
| Next by Date: | Re: how to extract the elements of a list of vectors in a fixed position?, Alan Hochberg |
| Previous by Thread: | how to extract the elements of a list of vectors in a fixed position?, carol white |
| Next by Thread: | Re: how to extract the elements of a list of vectors in a fixed position?, Alan Hochberg |
| Indexes: | [Date] [Thread] [Top] [All Lists] |