s-news
[Top] [All Lists]

Re: converting a data frame to a list

To: "Walter R. Paczkowski" <dataanalytics@earthlink.net>
Subject: Re: converting a data frame to a list
From: Dimitrios Rizopoulos <Dimitris.Rizopoulos@med.kuleuven.be>
Date: Sat, 20 May 2006 19:20:45 +0200
Cc: s-news@wubios.wustl.edu
In-reply-to: <7.0.1.0.2.20060520124544.033b4968@earthlink.net>
References: <7.0.1.0.2.20060520124544.033b4968@earthlink.net>
User-agent: Internet Messaging Program (IMP) 3.2-cvs
you could try something along these lines:

dat <- data.frame(x = rnorm(100),
                  y = sample(letters, 100, TRUE),
                  z = sample(LETTERS, 100, TRUE),
                  w = runif(100),
                  k = rexp(100, 2),
                  m = rep(c("yes", "No"), 50))
###################
index <- lapply(seq(1, ncol(dat), 2), seq, length = 2)
list.dat <- lapply(index, "[", x = dat)


I hope it helps.

Best,
Dimitris

---- 
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting "Walter R. Paczkowski" <dataanalytics@earthlink.net>:

> 
> 
> 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
> 
> 
> 
> 
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm


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