[19130] in s-news-athena
[S] converting a list of dataframes into a single dataframe
daemon@ATHENA.MIT.EDU (John.Gavin@wdr.com)
Tue Sep 7 15:38:02 1999
From: John.Gavin@wdr.com
Date: Tue, 7 Sep 1999 20:33:14 +0100
Message-Id: <H00004ac0a5d9235@MHS>
Mime-Version: 1.0
To: s-news@wubios.wustl.edu
Content-Type: text/plain; charset=US-ASCII; name="BDY.TXT"
Content-Disposition: inline; filename="BDY.TXT"
Content-Transfer-Encoding: 7bit
Hi,
I have a long list of data frames.
Each data frame has identical columns
(same number of columns, in the same order
and of the same class).
How can I produce a new single data frame formed by
stacking each data frame in the list one on
top of the other.
I am aware of the 'data - merge' command but
the list is too long to do two data frames at a time.
In effect, I want to reverse the data split command.
Also each data frame may contain 'factor' and 'ordered' columns
so I want to preserve the original labels.
I am on SPlus 2000 on NT 4.
Example: given the list 'input' I want to produce
the data frame 'output'.
input <- list(
a = data.frame(
x = c(1.0,2,3),
y = factor(c(1,1,2), levels = 1:3, labels = c("f1", "f2", "f3") ),
z = ordered(c(2,2,1), levels = 1:3, labels = c("o1","o2","o3") )
) ,
b = data.frame(
x = c(4,5),
y = factor(c(3,3), levels = 1:3, labels = c("f1","f2","f3") ),
z = ordered(c(3,2), levels = 1:3, labels = c("o1", "o2","o3") )
)
)
> input
$a:
x y z
1 1 f1 o2
2 2 f1 o2
3 3 f2 o1
$b:
x y z
1 4 f3 o3
2 5 f3 o2
output <- data.frame(
x = c(1.0,2,3,4,5) ,
y = factor(c(1,1,2,3,3), levels = 1:3, labels = c("f1", "f2",
"f3") ) ,
z = ordered(c(2,2,1,3,2), levels = 1:3, labels =
c("o1","o2","o3") )
)
> output
x y z
1 1 f1 o2
2 2 f1 o2
3 3 f2 o1
4 4 f3 o3
5 5 f3 o2
Thanks,
John.
john.gavin@wdr.com
John Gavin
Quantitative Risk Models and Statistics
Warburg Dillon Read
1 Finsbury Ave
London EC2M 2PP, UK
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news