[18994] in s-news-athena
[S] transpose and expand dataframe
daemon@ATHENA.MIT.EDU (John P McKinlay)
Sat Aug 21 00:04:41 1999
Message-Id: <3.0.1.32.19990821115649.00a616e0@mail.bigpond.com>
Date: Sat, 21 Aug 1999 11:56:49
To: s-news@wubios.wustl.edu
From: John P McKinlay <john.mckinlay@bigpond.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
I've spent an appropriate amount of "struggle-time" trying to do this, now
to the list!
I'm looking an efficient way of turning
> adf<-data.frame(A=c(4,4,4,7,7,7,7,9,9),
B=c(2,3,4,3,7,8,6,4,8),
count=c(23,12,34,7,56,32,10,16,3))
> adf
A B count
1 4 2 23
2 4 3 12
3 4 4 34
4 7 3 7
5 7 7 56
6 7 8 32
7 7 6 10
8 9 4 16
9 9 8 3
into a dataframe which looks like:
A 2 3 4 6 7 8
1 4 23 12 34 0 0 0
2 7 0 7 0 0 56 32
3 9 0 0 16 0 0 3
Sort of a transpose on B, filling the resulting dataframe with either count
or 0. Concerning adf, B is unique within levels of A. For the real data,
the resulting dataframes will be of the order 1000 x 50 (ie 1000 unique A
and 50 unique B). If it is possible to generalise this problem to accept
multiple A's, that would also be handy. I'm sure there must a non-looping
way to do this, but I couldn't figure one out.
Reply direct and I'll summarise. (Using Win NT, S+4.5)
Thanks in advance.
John McKinlay
email: john.mckinlay@bigpond.com
--
John McKinlay
Phone: 08 92468440 -w
08 92465812 -h
email: john.mckinlay@bigpond.com or john.mckinlay@fish.wa.gov.au
-----------------------------------------------------------------------
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