s-news
[Top] [All Lists]

Re: converting a data frame to a list

To: "Walter R. Paczkowski" <dataanalytics@earthlink.net>, s-news@wubios.wustl.edu
Subject: Re: converting a data frame to a list
From: "Liaw, Andy" <andy_liaw@merck.com>
Date: Mon, 22 May 2006 23:26:03 -0400
Doing lapply() "backward" should work; e.g.,
 
idx <- split(1:6, rep(1:3, each=2))
mylist <- lapply(idx, function(i) mydata[,i])

Cheers,
Andy

  _____  

From: s-news-owner@lists.biostat.wustl.edu on behalf of Walter R. Paczkowski
Sent: Sat 5/20/2006 12:51 PM
To: s-news@wubios.wustl.edu
Subject: [S] converting a data frame to a list


Hi,

Suppose I have a data frame with n rows and six columns.  I want to create a
list that has, say, 3 components each with all n rows but with the first
having the first two columns of the original data frame, the second
component having the next two columns, and the third having the last two
columns.  SPLIT doesn't work since it splits the rows.  I want to split the
columns.  Transpose doesn't work that I can see.  Any suggestions?

Thanks,

Walt Paczkowski


_________________________________

Walter R. Paczkowski, Ph.D.
Data Analytics Corp.
44 Hamilton Lane
Plainsboro, NJ  08536
(V) 609-936-8999
(F) 609-936-3733




------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments, contains 
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New 
Jersey, USA 08889), and/or its affiliates (which may be known outside the 
United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as 
Banyu) that may be confidential, proprietary copyrighted and/or legally 
privileged. It is intended solely for the use of the individual or entity named 
on this message.  If you are not the intended recipient, and have received this 
message in error, please notify us immediately by reply e-mail and then delete 
it from your system.
------------------------------------------------------------------------------

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